sorting hashmap by key in java 8

Solutions on MaxInterview for sorting hashmap by key in java 8 by the best coders in the world

showing results for - "sorting hashmap by key in java 8"
Charley
03 Apr 2019
1Map<String, String> newMapSortedByKey = sample.entrySet().stream()
2                .sorted((e1,e2) -> e1.getKey().compareTo(e2.getKey()))
3                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1,e2) -> e1, LinkedHashMap::new));
4