天天看点

统计数组中重复元素个数

/**
     * 循环统计数组或集合中的重复元素个数
     * @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