프로그래머스에 해쉬 문제 풀다가 조합공식에 넣을 중복되는 원소 갯수 체크하는 방법이 필요했음.

 

샘플 데이터의 카테고리 (headgear, eyewear) 별로 원소 갯수.

String str[][] = 
     {
     {"yellowhat", "headgear"}, 
     {"bluesunglasses", "eyewear"}, 
     {"green_turban", "headgear"}
     };

HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
        for(String[] str : clothes) {
        	hashMap.put(str[1], hashMap.getOrDefault(str[1], 0) + 1 );
        }
        System.out.println(hashMap);
        
        
for(Entry<String, Integer> str : hashMap.entrySet())
        {
        	System.out.println("value : " + str.getValue());
        }