【发布时间】:2015-01-28 21:40:11
【问题描述】:
我需要从用户那里获取字符串输入并在某个数组中搜索它,然后我需要对结果进行排序
- 最相似的东西
- ....
- ......
like 用户的输入将类似于“The mos”,并将其显示为结果。
这是我为它编写的方法,但我无法完成它: (这是一些作业,我需要使用自己编写的数据结构,我需要使用哈希图来创建电话簿。如果您需要我的其他课程,我可以更新问题。)
public static void searchByName()
{
System.out.println("Name: ");
String nameSearch = input.next();
for(int i=0; i < contactList.bucket.length; i++)
{
Iterator itr = (LinkedListIterator<HashEntry<Integer,Person>>) contactList.bucket[i].iterator();
while(itr.hasNext()){
HashEntry<Integer,Person> he = (HashEntry<Integer, Person>) itr.next();
int similarity = nameSearch.compareTo(he.getValue().getName());
HashEntry<Integer,String>[] similarArray = null;
for(int x=0; x < contactList.bucket[i].size; x++)
{
similarArray[x] = new HashEntry(similarity, he.getValue().getName());
}//end of for loop
}//end of while loop
}//end of for loop
}//end of searchByName
【问题讨论】:
-
我希望看到您的缩进已修复。
-
谢谢,希望有人能帮帮我
-
请澄清:您想要简单地完成输入,您想要更正建议还是两者都想要?
-
您需要什么样的帮助?您知道如何判断哪个元素最接近输入吗?您需要算法、输出或其他方面的帮助吗?
-
@midor 想要数组中最相似的值。它将是一个联系人列表,因此当您键入一些文本信息时,它会显示最相似的结果。是的,结果应该不止一个。
标签: java data-structures hash hashmap