Say I have a list of objects called Student. Object Student is defined as
public class Student {
private String studentName;
private String courseTaking;
}
In the list of students, there can be multiple student objects with the same studentName but different courseTaking. Now, I want to turn the list of students into a map of studentName and courseTaking like so
Map<String, Set<String>>
The key is studentName, and the value is all of the courseTaking of the same student put together as a Set. How can I do this using stream() & collect()?
Studentobjects for each course the student is taking ? Definitely doesn't feel right. The courses should be an array in theStudentobject directly.students.stream().collect(groupingBy(Student::getStudentName, mapping(Student::getCourseTaking, toSet())))