标签:rar [] == max ati map 最大 test hash
Java中如何计算字符串中字符出现的最大次数
import java.util.HashMap;
import java.util.Map;
public class TestStringSum {
public static void main(String[] args) {
String str = "abcdefgaaabbb";
int max = 0;
Map<Character, Integer> map = new HashMap<Character,Integer>(str.length());
for(char c :str.toCharArray()){
Integer i = map.get(c);
int value = (i==null)?0:i;
map.put(c, ++value);
max = value>max?value:max;
}
System.out.println(max); // 4
}
}
标签:rar [] == max ati map 最大 test hash
原文地址:https://www.cnblogs.com/hglibin/p/9996875.html