Java year isAfter()方法及示例
Java中Year类的isAfter()方法用于检查当前的Year对象是否在作为该方法参数的指定年份之后。
语法:
public boolean isAfter(Year otherYear)
参数 :它接受一个单一的参数otherYear,当前的Year对象将被与之比较。
返回值 :如果这个Year对象的值在作为该方法参数指定的Year对象的值之后,它返回一个布尔值True,否则它返回False。
以下程序说明了Java中Year的isAfter()方法:
程序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));
}
}
输出:
true
程序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));
}
}
输出:
false
参考资料 : https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#isAfter-java.time.Year-