🔸 TLDR
For dates representing birthdays:
▪️ min() → oldest person 👴
- ▪️ max() → youngest person 👶
Why?
Because Java compares dates chronologically:
PAST ←────────────→ FUTURE older younger
So the most recent date is the MAX. ✅
Let's check several Java date/time classes.
🔸 JAVA.UTIL.DATE
✅ 2005 is the youngest.
Date natural ordering goes from earlier to later.
#Date
🔸 JAVA.TIME.LOCALDATE
✅ 2005-01-01
Perfect for birthdays because LocalDate represents a date without a time or timezone.
#LocalDate
🔸 JAVA.TIME.LOCALDATETIME
✅ 2005-01-01T10:00
Again: later date-time = greater value = MAX.
#LocalDateTime
🔸 JAVA.TIME.ZONEDDATETIME
ZonedDateTime represents a date and time with a time zone 🌍
✅ The 2005 value is the youngest.
Unlike LocalDateTime, a ZonedDateTime can be mapped to an exact point on the global timeline.
That matters because:
and
have the same local clock time, but they do not represent the same instant.
Using:
makes the intent explicit:
▪️ Earlier instant → smaller
▪️ Later instant → greater
▪️ Latest instant → MAX → youngest/newest
#ZonedDateTime
🔸 JAVA.TIME.INSTANT
✅ 2005-01-01T00:00:00Z
Instant represents an actual point on the UTC timeline.
Later instant → greater value → MAX.
#Instant
🔸 TAKEAWAYS
▪️ Earliest date = MIN
▪️ Latest date = MAX
▪️ Oldest birthday = MIN
▪️ Youngest birthday = MAX
▪️ Date, LocalDate, LocalDateTime and Instant follow chronological ordering
▪️ Date, LocalDate, LocalDateTime, ZonedDateTime and Instant can all be used to find the latest value with max(), but ZonedDateTime lets you compare actual moments across time zones.
▪️ When in doubt, think: later on the timeline = greater
So if somebody asks:
"Find the youngest person."
Your Stream probably wants:
Not min(). 🎯
#Java #Java27 #DateTime #JavaTime #Streams #Comparator #LocalDate #LocalDateTime #Instant #TimeZone #JavaDeveloper #Programming #JavaCertification #OCPJava
Go further with Java certification:
Java👇
Spring👇
SpringBook👇
JavaFullstackBook👇