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 hm = new HashMap(); for (String str : array) { if(hm.containsKey(str)) { hm.put(str, (int)hm.get(str)+1); } else hm.put(str, 1); } System.out.println(hm); } }
时间: 2024-10-20 19:59:07