I am trying to group by a collection by a value that appears in my object as a list.
This is the model that I have
public class Student {
String s
Summing up the comments above, the collected wisdom would suggest:
Map<String, List<Student>> x = studlist.stream()
.flatMap(student -> student.getStud_location().stream().map(loc -> new AbstractMap.SimpleEntry<>(loc, student)))
.collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, toList())));
As an alternate approach, if you don't mind the Students in each list containing only that location, you might consider flattening the Student list to Students with only one location:
Map<String, List<Student>> x = studlist.stream()
.flatMap( student ->
student.stud_location.stream().map( loc ->
new Student(student.stud_id, student.stud_name, loc))
).collect(Collectors.groupingBy( student -> student.stud_location.get(0)));