I have list of records as below. I want to fetch the latest record based on date and set its name as 'H'. In the same way I want to set 'L' as name for all remaining records.
List<Student> studentList = new ArrayList<>();
try {
studentList.add(new Student("A", new SimpleDateFormat("dd-MM-yyyy").parse("01-01-1990")));
studentList.add(new Student("B", new SimpleDateFormat("dd-MM-yyyy").parse("01-01-2010")));
studentList.add(new Student("C", new SimpleDateFormat("dd-MM-yyyy").parse("01-01-2011")));
studentList.add(new Student("D", new SimpleDateFormat("dd-MM-yyyy").parse("01-01-2012")));
studentList.add(new Student("E", new SimpleDateFormat("dd-MM-yyyy").parse("01-01-2018")));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Student student = Collections.max(studentList, Comparator.comparing(s -> s.getDate()));
I've tried as above but here I can set name only for latest record but I'm unable to set name for all other remaining records.
Any help would be appreciated.