Thursday, September 4, 2025
HomeLanguagesJavaYear isAfter() method in Java with Examples

Year isAfter() method in Java with Examples

The isAfter() method of Year class in Java is used to check if this current Year object is after the Year specified as parameter to this method.

Syntax:

public boolean isAfter(Year otherYear)

Parameter: It accepts a single parameter otherYear with which the current Year object is to be compared.

Return Value: It returns a boolean True value if this Year object’s value is after the value of Year object specified as a parameter to the method, otherwise it returns False.

Below programs illustrate the isAfter() method of Year in Java:
Program 1:




// Program to illustrate the isAfter() method
  
import java.util.*;
import java.time.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Create first Year object
        Year firstYear = Year.of(2018);
  
        // Create second Year object
        Year secondYear = Year.of(1997);
  
        // Check if this year object's value is
        // after the specified Year or not
        System.out.println(firstYear.isAfter(secondYear));
    }
}


Output:

true

Program 2:




// Program to illustrate the isAfter() method
  
import java.util.*;
import java.time.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Create first Year object
        Year firstYear = Year.of(1997);
  
        // Create second Year object
        Year secondYear = Year.of(2018);
  
        // Check if this year object's value is
        // after the specified Year or not
        System.out.println(firstYear.isAfter(secondYear));
    }
}


Output:

false

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#isAfter-java.time.Year-

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS