Java Integer compareTo()方法具有什么功能呢?
下文笔者将讲述 java.lang.Integer compareTo()方法的功能简介说明,如下所示:
比较两个整数对象中的数值
java.lang.Integer compareTo()的功能
java.lang.Integer.compareTo()的功能:比较两个整数对象中的数值
java.lang.Integer.compareTo()的语法
语法 public int compareTo(Integer anotherInteger) 参数 anotherInteger:待比较的整数对象 返回值 当两个整数对象中的值相等时,则返回0 当整数数值小于整数参数中的值时,则返回一个大于0 的数 当整数数值大于整数参数中的值时,则返回一个小于0 的数例:
package com.java.other;
import org.junit.Test;
public class other {
/**
* java265.com Integer类的示例分享
*
* @throws Exception
*/
@Test
public void test() throws Exception {
Integer i = 99;
Integer j = 990;
Integer k = 99;
System.out.println(i.compareTo(j));
System.out.println(i.compareTo(k));
System.out.println(j.compareTo(i));
}
}
-----运行以上代码,将输出以下信息-----
-1
0
1
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


