I have map Map countByType and I want to have a list which has sorted (min to max) keys by their corresponding values. My try is:
Map countByType
Map map = new HashMap<>(); map.put(1, "B"); map.put(2, "C"); map.put(3, "D"); map.put(4, "A"); List list = map.values() .stream() .sorted() .collect(Collectors.toList());
Output: [A, B, C, D]
[A, B, C, D]