Java stream averagingInt by multiple parameters
6
I have a class
static class Student {
private String surname;
private String firstName;
private String secondName;
private int yearOfBirth;
private int course;
private int groupNumber;
private int mathGrade;
private int engGrade;
private int physicGrade;
private int programmingGrade;
private int chemistryGrade;
And there is a method that adds students to the map for the course
public Map<Integer, Double> averageInt(List<Student> students) {
Map<Integer, Double> map2 = students.stream()
.collect(Collectors.groupingBy(Student::getCourse,
Collectors.averagingInt(Student::getEngGrade)));
return map2;
}
However, I need several average values in one map at the same time.
Not only engGrade, but also mathGrade, programmingGrade and so on. I think the code in this case should be in the format Map<Integer, List<Double>>
but I don’t know how to do it. Tell me please
For example, I now display "Course = 1, average eng grade = ..."
And I need to display "Course = 1, average eng grade = ..., average math grade = ..."
, ie so that there are multiple Double values in the map
java collections java-stream
Add a comment
|