The isBefore() method of Year class in Java is used to check if this current YearMonth object is before the YearMonth specified as parameter to this method.
Syntax:
public boolean isBefore(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 before the value of YearMonth object specified as a parameter to the method, otherwise it returns False.
Below programs illustrate the YearMonth.isBefore() method in Java:
Program 1:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
YearMonth yearMonth1
= YearMonth.of( 2018 , 3 );
YearMonth yearMonth2
= YearMonth.of( 1997 , 4 );
System.out.println(yearMonth1
.isBefore(yearMonth2));
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
YearMonth yearMonth1
= YearMonth.of( 1997 , 3 );
YearMonth yearMonth2
= YearMonth.of( 2018 , 4 );
System.out.println(yearMonth1
.isBefore(yearMonth2));
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#isBefore-java.time.YearMonth-
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 Nov, 2018
Like Article
Save Article