The isAfter() method of Year class in Java is used to check if this current YearMonth object is after the YearMonth specified as parameter to this method.
Syntax:
public boolean isAfter(Year otherYearMonth)
Parameter: It accepts a single parameter otherYearMonth with which the current YearMonth object is to be compared.
Return Value: It returns a boolean True value if this YearMonth object’s value is after the value of YearMonth object specified as a parameter to the method, otherwise it returns False.
Below programs illustrate the YearMonth.isAfter() method 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 YearMonth yearMonth1 = YearMonth.of(2018, 3); // Create second Year object YearMonth yearMonth2 = YearMonth.of(1997, 4); // Check if this year-month object's value is // after the specified Year-month or not System.out.println(yearMonth1 .isAfter(yearMonth2)); } } |
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 YearMonth yearMonth1 = YearMonth.of(1997, 3); // Create second Year object YearMonth yearMonth2 = YearMonth.of(2018, 4); // Check if this year-month object's value is // after the specified Year-month or not System.out.println(yearMonth1 .isAfter(yearMonth2)); } } |
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#isAfter-java.time.YearMonth-
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- LocalDateTime isAfter() method in Java with Examples
- Instant isAfter() method in Java with Examples
- Year isAfter() method in Java with Examples
- LocalDate isAfter() method in Java with Examples
- LocalTime isAfter() method in Java with Examples
- OffsetTime isAfter() method in Java with examples
- OffsetDateTime isAfter() method in Java with examples
- MonthDay isAfter() Method in Java with Examples
- ChronoLocalDate isAfter() method in Java with Examples
- ChronoLocalDateTime isAfter() method in Java with Examples
- ChronoZonedDateTime isAfter() method in Java with Examples
- YearMonth isSupported(TemporalUnit) Method in Java with Examples
- YearMonth lengthOfYear() method in Java with Examples
- YearMonth isValidDay() method in Java with Examples
- YearMonth isLeapYear() method in Java with Examples
- YearMonth isBefore() method in Java with Examples
- YearMonth query() Method in Java with Examples
- YearMonth with() Method in Java with Examples
- YearMonth withYear() method in Java with Examples
- YearMonth withMonth() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

