Java Date Time - Year compareTo(Year other) example








Year compareTo(Year other) compares this year to another year.

Syntax

compareTo has the following syntax.

public int compareTo(Year other)

Example

The following example shows how to use compareTo.

import java.time.Year;
//from  ww w  .ja  v a  2s.c o m
public class Main {
  public static void main(String[] args) {
    
    Year y = Year.of(2014);

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

  }
}

The code above generates the following result.