I have map Map and I want to have a list which has sorted (min to max) keys by their corresponding values. My try is:
You say you want to sort by value, but you don't have that in your code. Pass a lambda (or method reference) to sorted to tell it how you want to sort.
And you want to get the keys; use map to transform entries to keys.
List types = countByType.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue))
.map(Map.Entry::getKey)
.collect(Collectors.toList());