java.time.Year compareTo()方法

java.time.Year.compareTo(Year other)方法将此年份与另一年度进行比较。

1 语法

public int compareTo(Year other)

2 参数

other:与另一年份比较,不是null。

3 返回值

比较器值,如果更小则为负,如果大于则为正值。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.time.Year compareTo()方法
 */
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

 

热门文章

优秀文章