代码如下:
public static void main(String[] args) { String str = "大批量,之前都没怎么注意过,这个问题确实不会,网上参考了下别人的,大体上是这个意思:" + "合并数据+事务的方法在较小数据量时,性能提高是很明显的,数据量较大时(1千万以上)," + "性能会急剧下降,这是由于此时数据量超过了innodb_buffer的容量,每次定位索引涉及较多的磁盘读写操作," + "性能下降较快。而使用合并数据+事务+有序数据的方式在数据量达到千万级以上表现依旧是良好,在数据量较大时," + "有序数据索引定位较为方便,不需要频繁对磁盘进行读写操作,所以可以维持较高的性能"; char[] chars = str.toCharArray(); HashMap<Character, Integer> map = new HashMap<Character, Integer>(); int max = 0; for (char c : chars) { if (map.containsKey(c)) { int oldnum = map.get(c); map.put(c, oldnum + 1); if (max < oldnum + 1) max = oldnum + 1; } else { map.put(c, 1); } } Set<Character> keys = map.keySet(); for (char c : keys) { if (map.get(c) == max) { System.out.println(c + "出现了" + map.get(c) + "次 次数最多 "); } else { System.out.println(c + "出现了" + map.get(c) + "次"); } } }