import java.util.HashMap; import java.util.Scanner; public class Demo01Map { public static void main(String[] args) { //1,使用Scanner获得用户输入的字符串 Scanner scanner = new Scanner(System.in); System.out.println("请输入一个字符串"); String str = scanner.next(); //2,创建Map集合,kep是字符串的字符,value是字符的个数 HashMapmap =new HashMap<>(); //3,4 for(char c :str.toCharArray()){ if(map.containsKey(c)){ Integer value =map.get(c); value++; map.put(c,value); }else{ map.put(c,1); } } for(Character key :map.keySet()){ Integer value = map.get(key); System.out.println(key+"="+value); } } }