题解 | #字符统计#注意边界#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
import java.util.*; import java.lang.*; import java.util.stream.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String raw = in.nextLine(); Map<Character,Integer> map = new HashMap<Character,Integer>(); for(char c: raw.toCharArray()){ map.merge(c,1,Integer::sum); } map.entrySet().stream().sorted(Comparator.comparing(Map.Entry<Character,Integer>::getValue).reversed().thenComparing(Map.Entry<Character,Integer>::getKey)).map(a->a.getKey()).forEach(System.out::print); } }