Java Date Time - Year equals(Object obj) example








Year equals(Object obj) checks if this year is equal to another year.

Syntax

equals has the following syntax.

public boolean equals(Object obj)

Example

The following example shows how to use equals.

import java.time.Year;
/*w w  w.j a  v a 2 s  .c om*/
public class Main {
  public static void main(String[] args) {
    
    Year y = Year.of(2014);

    System.out.println(y.equals(Year.of(2015)));

  }
}

The code above generates the following result.