首页javastringJava Data Type - 如何找到一个大字符串中出现频次最高的字符

Java Data Type - 如何找到一个大字符串中出现频次最高的字符

我们想知道如何找到一个大字符串中出现频次最高的字符。
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static final String LINE = "this is a test this is a test a test test";

    public static Map<Character, Integer> map = new HashMap<>();

    public static void main(String[] args) {

        for (Character c : LINE.toCharArray()) {

            Integer count = map.get(c);
            map.put(c, count != null ? count + 1 : 0);
        }
        System.out.println(Collections.max(map.values()));
    }
}