/**
* 循環統計數組或集合中的重複元素個數
* @param args
*/
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
String[] ss = {"白","黑","綠","白"};
for (int i = 0; i < ss.length; i++) {
if (map.get(ss[i]) != null) {
Integer num = (Integer) map.get(ss[i]);
num++;
map.put(ss[i], num);
} else {
map.put(ss[i], 1);
}
}
System.out.println(map);
}
轉載于:https://www.cnblogs.com/mengzw/p/3753248.html