String temp = str.replaceAll(strArray[i], "");
count = (str.length() - temp.length())/strArray[i].length();
if (count > result){
map.clear();
map.put(strArray[i], count);
result = count;
}
else if(count == result)
map.put(strArray[i], count);
}
return map;
}
public static void main(String args[]){
String[] strArray = {"11", "11", "2", "2", "4", "5", "4"};
HashMapresult = mostEle(strArray);
ArrayListc = new ArrayList(result.values());
Sets = result.keySet();
System.out.print("一共有"+ result.size() +"元素最多。它们分别是");
System.out.print(s);
System.out.println(",分别出现了"+ c.get(0) +"次。");
}
}
结果是:
一共有3元素最多。Examda提示:它们分别是[2, 11, 4],分别出现了2次。
一起交流学习请访问:Tore_m_1206686_21115_1_1.html">http://www.shangxueba.com/sTore_m_1206686_21115_1_1.html