Java Date Time - YearMonth equals(Object obj) example








YearMonth equals(Object obj) checks if this year-month is equal to another year-month.

The comparison is based on the time-line position of the year-months.

Syntax

equals has the following syntax.

public boolean equals(Object obj)

Example

The following example shows how to use equals.

import java.time.YearMonth;

public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    System.out.println(y.equals(YearMonth.now()));

  }
}

The code above generates the following result.