I have a set of Student - Set<Student> students
class Student{
String Id;
String getId(){ return Id;}
.....
}
I am trying to initialize a Map<String,List<StudentResult>> with the entries from set above:
Map<String,List<StudentResult>> studentResultMap = students.keySet().stream().collect(
Collectors.toMap(x -> x.getId(),new ArrayList<StudentResult>()));
But this wouldn't compile - how is this to be achieved?
new ArrayList<StudentResult>() does not make a correct argument for a Function parameter.
You need to use:
x -> new ArrayList<StudentResult>()
Side note: students.keySet() wouldn't compile either, if students is a Set. You can call stream on it directly:
students.stream().collect(Collectors.toMap(x -> x.getId(),
a -> new ArrayList<>()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With