public static void main(String[] args) {
String data = "hello world,every body!";
Map<Character,Integer> countMap = new HashMap<Character,Integer>();
for(int i=0;i<data.length();i++) {
char c = data.charAt(i);
if (countMap.containsKey(c)) {
countMap.put(c, countMap.get(c) + 1);
} else {
countMap.put(c, 1);
}
}
for(Map.Entry<Character, Integer> me:countMap.entrySet()){
System.out.println(me.getKey()+"\t" + me.getValue());
}
List<Character> list = new ArrayList<Character>();
int max=0;
for(Map.Entry<Character, Integer> me:countMap.entrySet()) {
if (me.getValue() < max) {
continue;
}
if (me.getValue() == max) {
list.add(me.getKey());
}
if(me.getValue() > max) {
list.clear();
max = me.getValue();
list.add(me.getKey());
}
}
System.out.println("*************************");
for(Character c:list){
System.out.println("次数出现最多的字母:"+c+" 出现次数为:"+ max);
}
}