I have group of students. First I want to group them by the marks. Then I want to further group those sets into same name students together.
Map<Integer,Map<String,List<String>>> groupping = students.stream()
.collect(Collectors.groupingBy(Student::getMarks,
Collectors.mapping(Student::getName,Collectors.toList())));
I am getting a error saying,
Non-static method cannot be refered from a static context.
Yes. I am pretty much aware that I cannot refer a non-static method without having an instance. But with all these stream operations, I'm bit confused what has gone wrong really.
Rather than how to fix this; I really want to know what's going on here. Any of your inputs are appreciated!
Because If I write the below grouping is completely valid;
Map<Integer,List<Student>> m = students.stream().
collect(Collectors.groupingBy(Student::getMarks));
Here is my Student.java class (In case if you need it)
public class Student {
private String name;
private int marks;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMarks() {
return marks;
}
public void setMarks(int marks) {
this.marks = marks;
}
public Student(String name, int marks) {
this.name = name;
this.marks = marks;
}
@Override
public String toString() {
return name + ':' + marks ;
}
}