How to split a string into a map, grouping values by duplicate keys using streams?
问题 I want to convert the following String flString="view1:filedname11,view1:filedname12,view2:fieldname21"; to a Map<String,Set<String>> to get the key/value as below: view1=[filedname11,filedname12] view2=[fieldname21] I want to use Java 8 streams. I tried Arrays.stream(tokens) .map(a -> a.split(":")) .collect(Collectors.groupingBy( a -> a[0], Collectors.toList())); However the keys are also getting added to the value list. 回答1: You should use a Collectors::mapping to map the array to an