java.lang.Short.equals()方法实例
java.lang.Short.equals() 方法比较此对象与指定对象。其结果是true,当且仅当参数不为null,并且包含相同的short值作为此short 对象。
声明
以下是java.lang.Short.equals()方法的声明
public boolean equals(Object obj)
参数
-
obj -- 这是要比较的对象。
返回值
如果对象是相同此方法返回true,否则返回false。
异常
-
NA
例子
下面的例子显示java.lang.Short.equals()方法的使用。
package com.yiibai; import java.lang.*; public class ShortDemo { public static void main(String[] args) { // create short object and assign value to it short shortNum1 = 200, shortNum2 = 200, shortNum3 = 50; Short ShortObj1 = new Short(shortNum1); Short ShortObj2 = new Short(shortNum2); Short ShortObj3 = new Short(shortNum3); // returs false as both object contains different short value boolean val = ShortObj1.equals(ShortObj3); System.out.println("shortObj1 and shortObj3 have same value : " + val); // returns true as both object contains same short value val = ShortObj1.equals(ShortObj2); System.out.println("shortObj1 and shortObj2 have same value : " + val); } }
让我们来编译和运行上面的程序,这将产生以下结果:
shortObj1 and shortObj3 have same value : false shortObj1 and shortObj2 have same value : true