Java Date Time - MonthDay compareTo(MonthDay other) example








MonthDay compareTo(MonthDay other) compares this month-day to another month-day.

Syntax

compareTo has the following syntax.

public int compareTo(MonthDay other)

Example

The following example shows how to use compareTo.

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

  }
}

The code above generates the following result.