當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Year isAfter()用法及代碼示例


Java中Year類的isAfter()方法用於檢查當前的Year對象是否在指定為Year的該方法指定的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-



相關用法


注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 Year isAfter() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。