📜  在 java 8 中按键排序 hashmap - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:09.749000             🧑  作者: Mango

代码示例1
Map newMapSortedByKey = sample.entrySet().stream()
                .sorted((e1,e2) -> e1.getKey().compareTo(e2.getKey()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1,e2) -> e1, LinkedHashMap::new));