Here is an example of determining maximum and minimum between two dates and among more than two dates.
import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; public class MaxMinDate { public static void main(String[] args) { // First let's create two date objects LocalDate date1 = LocalDate.of(2020, 3, 12); LocalDate date2 = LocalDate.of(2020, 7, 15); // To determine the maximum or minimum date we can use method isAfter or isBefore method if (date1.isAfter(date2)) { System.out.println("Maximum Date : " + date1); System.out.println("Minimum Date : " + date2); } else { System.out.println("Maximum Date : " + date2); System.out.println("Minimum Date : " + date1); } // Now let's see how we can find the maximum and minimum date among more than two dates. // Let's create more date objects LocalDate date3 = LocalDate.of(2020, 1, 13); LocalDate date4 = LocalDate.of(2020, 3, 20); LocalDate date5 = LocalDate.of(2020, 7, 5); // Add all the date objects in an array list so that we can use utility methods of Collections class ArrayList<LocalDate> dateList = new ArrayList<>(); dateList.add(date1); dateList.add(date2); dateList.add(date3); dateList.add(date4); dateList.add(date5); LocalDate maxDate = Collections.max(dateList); LocalDate minDate = Collections.min(dateList); System.out.println("The maximum date is " + maxDate); System.out.println("The minimum date is " + minDate); } }