Friday, June 12, 2026
HomeLanguagesJavaMonthDay isAfter() Method in Java with Examples

MonthDay isAfter() Method in Java with Examples

isAfter() method of the MonthDay class used to check if this MonthDay is after the MonthDay passed as parameter or not. This method returns a boolean value showing the same.

Syntax:

public boolean isAfter(MonthDay other)

Parameters: This method accepts one parameter other which is the other month-day to compare to.

Return value: This method returns true if this MonthDay is after the specified MonthDay else it returns false.

Below programs illustrate the isAfter() method:
Program 1:




// Java program to demonstrate
// MonthDay.isAfter() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay month = MonthDay.parse("--10-12");
  
        // create other MonthDay object
        MonthDay othermonth = MonthDay.parse("--11-12");
  
        // apply isAfter() method
        boolean value = month.isAfter(othermonth);
  
        // print instance
        System.out.println("monthday:"
                           + month + " is after monthday:"
                           + othermonth + " = "
                           + value);
    }
}


Output:

monthday:--10-12 is after monthday:--11-12 = false

Program 2:




// Java program to demonstrate
// MonthDay.isAfter() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay month = MonthDay.parse("--10-12");
  
        // create other MonthDay object
        MonthDay othermonth = MonthDay.parse("--09-12");
  
        // apply isAfter() method
        boolean value = month.isAfter(othermonth);
  
        // print instance
        System.out.println("monthday:"
                           + month + " is after monthday:"
                           + othermonth + " = "
                           + value);
    }
}


Output:

monthday:--10-12 is after monthday:--09-12 = true

References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#isAfter(java.time.MonthDay)

RELATED ARTICLES

4 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS