Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocalDate: equals vs isEqual

LocalDate in Java has two similar methods equals and isEqual.

What's the difference between them? When do they output different results?

like image 447
AlexElin Avatar asked Dec 18 '22 11:12

AlexElin


1 Answers

LocalDate.equals, like most other equals method implementations, will always return false if you pass it something other than a LocalDate, even if they represent the same day:

System.out.println(LocalDate.now().equals(HijrahDate.now())); // false

ChronoLocalDate.isEqual compares whether the two dates are the same day, i.e. the same point on the local time line:

System.out.println(LocalDate.now().isEqual(HijrahDate.now())); // true
like image 91
Sweeper Avatar answered Dec 31 '22 16:12

Sweeper