I have a list of raw student data as mentioned below.
[
{
section : 1A
branch : science
studentName : abc
marks : 50
},
{
section : 1A
branch : science
studentName : sss
marks : 20
},
{
section : 1A
branch : science
studentName : asd
marks : 40
},
{
section : 1A
branch : Maths
studentName : www
marks : 10
},
{
section : 1A
branch : Maths
studentName : abc
marks : 70
},
{
section : 1A
branch : Maths
studentName : abc
marks : 86
},
{
section : 2A
branch : Maths
studentName : abc
marks : 55
},
{
section : 2A
branch : Maths
studentName : abc
marks : 89
},
{
section : 2A
branch : Maths
studentName : abc
marks :12
},
{
section : 2A
branch : physical
studentName : abc
marks :passed
},
{
section : 2A
branch : physical
studentName : abc
marks :failed
},
]
Now I want to transform this data into following format section wise: I am want the minimum marks and max marks for all students for particular subject. Same i want to do across all section. Basically I want to see what is the min and max marks for all the subject across all sections.
I have one more subject "physical test" and value is in pass and fail. I want to know how many are failed including above details. Now i have to declare this variable as String as I may contain actual marks or pass/fail. do you have any suggestions?
section 1A:
science : 20-50(min-max)
math : (10-86)(min-max)
section 2S:
science : 20-50(min-max)
math : (12-89)(min-max)
I am able to map sec to listofstudents using below code.
Map<String, List<Student>> map2 = studentsList.stream().collect(Collectors
.groupingBy(Student::getSection, HashMap::new, Collectors.toCollection(ArrayList::new)));
I am receiving that value as passed/failed from my source system and I can not change that. I have defined that variable as String as it may contain marks as Integer or string(passed/failed). I have been trying to write clean code using streams with avoiding too many loops and if statements but I am not able to do so. If subject have marks than group them as min-max if subject have passed/failed value than noOfFailed_totalstudents.
I am not able to do it using java streams. Please help. I am also trying it and will update if done.