我想知道如何搜索字符串的ArrayList,以查找我创建的“行程”对象中最常见的“目标”(其中包含不同目标的列表。 )在数组列表中搜索最常见的字符串
到目前为止,我有:
public static String commonName(ArrayList<Itinerary> itinerary){
int count = 0;
int total = 0;
ArrayList<String> names = new ArrayList<String>();
Iterator<String>itr2 = names.iterator();
while(itr.hasNext()){
Itinerary temp = itr.next();
if(temp.iterator().hasNext()){ //if its has destinations
// Destination object in itinerary object
Destination temp2 = temp.iterator().next();
String name = temp2.getDestination().toLowerCase().replace(" ", "");
if(names.contains(name)){
count = count + 1;
//do something with counting the occurence of string name here
}
我在做一个算法来搜索最常出现的字符串或字符串数组,如果出现平局的问题;然后显示找到该字符串的'行程对象'的数量(参数值)。任何帮助都会很棒,谢谢!
添加到每一行文字描述的Java代码说什么评论是没有用的,因为事实上它是分心和丑陋。 – 2010-02-18 19:57:21
为了增加保罗的观点,当你改变代码但不更新评论以反映改变 – mfeingold 2010-02-18 20:07:19