Short類的equals()方法是Java中的內置方法,用於將給定的對象與Short實例調用equals()方法進行比較。
用法
ShortObject.equals(Object a)
參數:它接受一個Object類型的對象a作為輸入,該對象將與調用equals方法的Short對象的實例進行比較。
返回值:它返回一個布爾值。如果“ a”的值等於ShortObject的值,則返回true。
下麵是Java中equals()方法的實現:
示例1:
// Java code to demonstrate
// Short equals() method
class GFG {
public static void main(String[] args)
{
// creating a Short object
Short a = new Short("20");
// creating a Short object
Short b = new Short("20");
// equals method in Short class
boolean output = a.equals(b);
// Printing the output
System.out.println("Does " + a
+ " equals " + b
+ " : " + output);
}
}
輸出:
Does 20 equals 20 : true
示例2:
// Java code to demonstrate
// Short equals() method
class GFG {
public static void main(String[] args)
{
// creating a Short object
Short a = new Short("2");
// creating a Short object
Short b = new Short("20");
// equals method in Short class
boolean output = a.equals(b);
// Printing the output
System.out.println("Does " + a
+ " equals " + b
+ " : " + output);
}
}
輸出:
Does 2 equals 20 : false
相關用法
- Java Shorts.indexOf(short[] array, short[] target)用法及代碼示例
- Java Shorts.indexOf(short[] array, short target)用法及代碼示例
- Java Short doubleValue()用法及代碼示例
- Java ShortBuffer put(int, short)用法及代碼示例
- Java Short hashCode()用法及代碼示例
- Java Short compareTo()用法及代碼示例
- Java Set equals()用法及代碼示例
- Java Map equals()用法及代碼示例
- Java ConcurrentSkipListMap equals()用法及代碼示例
- Java DecimalFormatSymbols equals()用法及代碼示例
- Java Double.equals()用法及代碼示例
- Java Optional equals()用法及代碼示例
- Java Writer equals()用法及代碼示例
- Java ChronoPeriod equals()用法及代碼示例
注:本文由純淨天空篩選整理自Sruti Rai大神的英文原創作品 Short equals() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。