Bartosz Czy┼╝owski Bartosz Czy┼╝owski - 1 year ago 154
Java Question

List to Map - Collectors.toMap()

I have a

List<String> abc
collection. I need to convert it into
Map<String, TreeSet<String>
where the key is the sorted string from
and this string before sorting is added to the TreeSet.
It is possible using

ex. pseudocode:
List<String> abc = ["ala","laa","qwe"]

Map<String, TreeSet<String> = {key = "aal" , values in treeset = "ala" , "laa"
key = "eqw" values in treeset = "qwe"}

Answer Source

groupingBy is the appropriate collector

Map<String, TreeSet<String>> map =
        s -> withSortedChars(s),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download