import java.util.HashMap; public class map1 { public static void main(String[] args) { String[] array = {"a","b","a","b","c","a","b","c","b"}; HashMap<String, Integer> hm = new HashMap<>(); for (String str : array) { if(hm.containsKey(str)) { hm.put(str, hm.get(str)+1); } else hm.put(str, 1); } System.out.println(hm); } }