我正在删除这个问题,因为网站领导层决定将我们的数据出售给 OpenAI。
如果您正在查找具有最大列表的密钥,您可以执行以下操作:
.max(Comparator.comparingInt(entry -> entry.getValue().size())).map(Entry::getKey)
所以你的代码可以是
String result = map.entrySet().stream()
.max(Comparator.comparingInt(entry -> entry.getValue().size()))
.map(Map.Entry::getKey)
.orElse(null); //if map is empty