我有一个名为ItemList的类,它用于提供自动完成文本字段的建议单词列表。因此,当用户键入一个字母时,会出现一个下拉菜单,其中包含建议单词列表。
我遇到了此功能所需的代码问题。
public List<Interface> SuggestedListOfWords(String prefix) {
int i = 0;
List<Interface> suggestedListOfWords = null;
while(i != wordsList.size()) {
String wordElement = wordsList.elementAt(i);
Item tempItem = new Item(wordElement);
//String item = wordsList.elementAt(i);
String itemName = tempItem.name;
int compareResult = itemName.compareTo(prefix);
if(compareResult == 0) {
}
i++;
}
return suggestedListOfWords;
}
有什么建议吗?
编辑:
for (String s : wordsList) {
if (s.startsWith(prefix))
phrases.add(s);
}
短语的类型为List<Interface>
它在这里抱怨add语句?
答案 0 :(得分:1)
对于这类事情,Trie
是一个很好的数据结构。
答案 1 :(得分:0)
的问题
phrases.add(s);
phrases
是List < Interface >
,
s
是String
。
phrases
持有Interfaces
,您正试图在其中添加String
。