Elegantly create map with object fields as key/value from object stream in Java 8
I have the following class class Person { public String name; public int age; public List<String> hobbies; Person(String name, int age, List<String> hobbies) {this.name = name; this.age = age; this.hobbies = hobbies;} } How do I create a Map of age to hobbies like Map<Integer, Set<String>> ? The Java 8 way I cooked up is: Map<Integer, Set<String>> collect8 = persons.stream() .collect( toMap( p -> p.age, p -> p.hobbies.stream().collect(toSet()), (hobbies1, hobbies2) -> Stream.concat(hobbies1.stream(), hobbies2.stream()).collect(toSet()) ) ); Is there a more idiomatic way of doing this with