您说要按值排序,但是您的代码中没有。传递一个lambda(或方法引用)
sorted来告诉它您想如何排序。
而您想获得钥匙;用于
map将条目转换为键。
List<Type> types = countByType.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .map(Map.Entry::getKey) .collect(Collectors.toList());

您说要按值排序,但是您的代码中没有。传递一个lambda(或方法引用)
sorted来告诉它您想如何排序。
而您想获得钥匙;用于
map将条目转换为键。
List<Type> types = countByType.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .map(Map.Entry::getKey) .collect(Collectors.toList());