The isBefore() method of Year class in Java is used to check if this current Year object is before the Year specified as parameter to this method.
Syntax:
public boolean isBefore(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 before the value of Year object specified as a parameter to the method, otherwise it returns False.
Below programs illustrate the isBefore() method of Year in Java:
Program 1:
// Program to illustrate the isBefore() 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 // before the specified Year or not System.out.println(firstYear.isBefore(secondYear)); } } |
false
Program 2:
// Program to illustrate the isBefore() 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 // before the specified Year or not System.out.println(firstYear.isBefore(secondYear)); } } |
true
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#isBefore-java.time.Year-
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:
- Instant isBefore() method in Java with Examples
- LocalDate isBefore() method in Java with Examples
- LocalDateTime isBefore() method in Java with Examples
- YearMonth isBefore() method in Java with Examples
- LocalTime isBefore() method in Java with Examples
- OffsetTime isBefore() method in Java with examples
- OffsetDateTime isBefore() method in Java with examples
- MonthDay isBefore() Method in Java with Examples
- ChronoLocalDate isBefore() method in Java with Examples
- ChronoLocalDateTime isBefore() method in Java with Examples
- ChronoZonedDateTime isBefore() method in Java with Examples
- Year get() method in Java with Examples
- Year plusYears() Method in Java with Examples
- Year minusYears() method in Java with Examples
- Year getLong() method in Java with Examples
- Year from() Method in Java with Examples
- Year adjustInto() Method in Java with Examples
- Year now() method in Java with examples
- Year length() method in Java with Examples
- Year isLeap() 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.

