获取字符串中出现最多的字符 (HashMap()储存)

import java.util.HashMap;
import java.util.Map;

public class number_of_character {


public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "asdasdugahjjaiosdhgbh";
Map map = new HashMap();
int len = s.length();


for(int i=0; i Character k = s.charAt(i);
map.put(k, (map.get(k) == null ? 1: map.get(k) + 1));
}

System.out.println(map);

char key = 0;
int min=-1;
for (Map.Entry entry : map.entrySet()) {
if(min {
min=entry.getValue();
key=entry.getKey();
}

}
System.out.println("Key = " + key + ", Value = " +min);
}

}

转载于:https://www.cnblogs.com/mumamuma/p/10485370.html

你可能感兴趣的:(获取字符串中出现最多的字符 (HashMap()储存))