Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

sorting hashmap by key in java 8

Map<String, String> 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));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sorting #hashmap #key #java
ADD COMMENT
Topic
Name
6+6 =