对LinkedHashMap进行排序 [英] Sorting LinkedHashMap
本文介绍了对LinkedHashMap进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果LinkedHashMap包含String和Integer,我如何根据其值对LinkedHashMap进行排序。所以我需要根据整数值对它进行排序。
非常感谢
How can I sort a LinkedHashMap based on its values given that the LinkedHashMap contains of String and Integer. So I need to sort it based on the Values which are Integers. Thanks a lot
推荐答案
现在使用Java 8流程非常简单:你不需要要排序的中间地图:
This is now quite a bit easier with Java 8 streams: you don't need the intermediate map to sort:
map.entrySet().stream()
.sorted(Map.Entry.comparingByValue())
.forEach(entry -> ... );
这篇关于对LinkedHashMap进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文