Year isBefore() method in Java with Examples
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:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year firstYear = Year.of( 2018 );
Year secondYear = Year.of( 1997 );
System.out.println(firstYear.isBefore(secondYear));
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year firstYear = Year.of( 1997 );
Year secondYear = Year.of( 2018 );
System.out.println(firstYear.isBefore(secondYear));
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#isBefore-java.time.Year-
Last Updated :
27 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...