/**
* map 按 key 升序排序
*/
private static Map<String, Object> sortByKey(Map<String, Object> map) {
Map<String, Object> result = new LinkedHashMap<>(map.size());
map.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
return result;
}
Map按 key 升序排序
最新推荐文章于 2025-09-15 10:32:33 发布
这段代码展示了如何使用Java 8的Stream API对Map的key进行升序排序,并将排序后的结果存入一个新的LinkedHashMap中,以保持插入顺序。
951

被折叠的 条评论
为什么被折叠?



