java.time.Year.compareTo() 方法示例



描述

java.time.Year.compareTo(Year other) 方法將本年與另一個年份進行比較。

宣告

以下是對 java.time.Year.compareTo(Year other) 方法的宣告。

public int compareTo(Year other)

引數

other - 要比較的其他年份,非空。

返回值

比較值,小於則為負數,大於則為正數。

示例

以下示例演示了 java.time.Year.compareTo(Year other) 方法的用法。

package com.tutorialspoint;

import java.time.Year;

public class YearDemo {
   public static void main(String[] args) {

      Year date = Year.of(2005);
      Year date1 = Year.of(2006);
      System.out.println(date.compareTo(date1));
   }
}

讓我們編譯並執行以上程式,這將產生以下結果 -

-1
廣告
© . All rights reserved.