案例分析图:
代码:
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("输入一个字符串"); String next = sc.nextLine(); char[] chars = next.toCharArray(); Arrays.sort(chars); HashMap<Character, Integer> map = new HashMap<>(); for (char aChar : chars) { if (map.containsKey(aChar)) { Integer value = map.get(aChar); value++; map.put(aChar,value); }else{ map.put(aChar,1); } } System.out.println(map); }
标签:字符,map,chars,System,value,案例,字符串,aChar From: https://www.cnblogs.com/shenziyi/p/16798131.html