Java Date Time - MonthDay equals(Object obj) example








MonthDay equals(Object obj) checks if this month-day is equal to another month-day.

Syntax

equals has the following syntax.

public boolean equals(Object obj)

Example

The following example shows how to use equals.

import java.time.Month;
import java.time.MonthDay;
//  w w  w . j a v a 2s . co m
public class Main {
  public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    
    System.out.println(m.equals(MonthDay.of(Month.APRIL, 1)));

  }
}

The code above generates the following result.