// 获取字符串 出现次数最多的字符 public static HashMapbut(String tar) { String[] split = tar.split(""); HashMap hashMap = new HashMap (); hashMap.put(split[0], 1); for (int i = 1; i < split.length; i++) { Integer integer = hashMap.get(split[i]); if(integer == null || integer == 0) { hashMap.put(split[i], 1); } else { hashMap.put(split[i], integer + 1); } } return hashMap; }
main
HashMapbut = but("cdfsccccdaasa"); int [] count = new int[but.size()]; int index = 0; for (String i : but.keySet()) { count[index] = but.get(i); index ++; System.out.println("Key: "+i+" Value: "+but.get(i)); } int max = count[0]; for (int i = 1; i < count.length; i++) { if(max < count[i]) { max = count[i]; } } System.out.println(max);



