Java:如何重置数组列表,使其为空 [已关闭]
我在 for 循环中将对象添加到此列表中。我希望每次调用该方法时此数组列表为空。arraylist<interface>
代码如下:
我想在这里清空的数组是建议的短语。
public List<Interface> returnSuggestedList(String prefix) {
String tempPrefix = prefix;
// suggestedPhrases = null;
//suggestedPhrases = new ArrayList<Interface>();
//Vector<String> list = new Vector<String>();
//List<Interface> interfaceList = new ArrayList<Interface>();
Collections.sort(wordsList);
System.out.println("Sorted Vector contains : " + wordsList);
int i = 0;
//List<String> selected = new ArrayList<String>();
for(String w:wordsList){
System.out.println(w);
if(w.startsWith(prefix.toLowerCase())) { // or .contains(), depending on
//selected.add(w); // what you want exactly
Item itemInt = new Item(w);
suggestedPhrases.add(itemInt);
}
}