We have a Student class as follows:
class Student {
private int marks;
private String studentName;
public int getMarks() {
r
You can use Collectors.groupingBy(classifier,mapFactory,downstream) method for this purpose:
List list = List.of(
new Student("abc", 30),
new Student("Abc", 32),
new Student("ABC", 35),
new Student("DEF", 40));
Map map = list.stream()
.collect(Collectors.groupingBy(
Student::getStudentName,
() -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER),
Collectors.summingInt(Student::getMarks)));
System.out.println(map); // {abc=97, DEF=40}