作者:桦7231227 | 来源:互联网 | 2022-11-25 19:56
1> Eran..:
您可以对条目进行流式处理,找到最大值并返回相应的键:
Integer maxKey =
map.entrySet()
.stream() // create a Stream of the entries of the Map
.max(Comparator.comparingInt(Map.Entry::getValue)) // find Entry with
// max value
.map(Map.Entry::getKey) // get corresponding key of that Entry
.orElse (null); // return a default value in case the Map is empty