I have a list that reads like
List<Student> students = Arrays.asList(
new Student("1234", "steve", LocalDate.parse("2019-09-01"), LocalDate.parse("2019-09-10")),
new Student("1234", "steve", LocalDate.parse("2019-09-11"), LocalDate.parse("2019-09-20")),
new Student("1234", "George", LocalDate.parse("2019-09-01"), LocalDate.parse("2019-09-10")));
The domain model of student holds four values Students = {String class_num, String name, LocalDate startDate, LocalDate endDate}
I am trying to group by the attribute name
and get min(startDate)
and max(endDate)
for distinct names found in the list.
The expected result for the above input should be
{{"1234", "steve", 2019-09-01, 2019-09-20},
{"1234", "George", 2019-09-01, 2019-09-10}}
//took the min of date for steve and max of date for steve
Can this be achieved through the use of stream api in java?