We use 3 lists ListA, ListB, ListC to save marks for 10 students in 3 subjects (A, B, C).
Subjects B and C are optional, so only a few out of 10 students have marks on these subjects
Class Student{
String studentName;
int marks;
}
ListA has entries for 10 students, ListB for 5 and ListC for 3 (which is also the size of the lists)
Want to know how we can summarize student grades for our subjects using java 8 steam.
I tried the following
List<Integer> list = IntStream.range(0,listA.size() -1).mapToObj(i -> listA.get(i).getMarks() +
listB.get(i).getMarks() +
listC.get(i).getMarks()).collect(Collectors.toList());;
There are 2 problems with this
a) It will throw an IndexOutOfBoundsException, since listB and listC do not have 10 elements
b) The return list is if is of type Integer and I want it to be of type Student.
Any inputs will be very helpful.
source
share