Java Short equals Example
Short class equals method example. This example shows you how to use equals method.
Short class equals method example. This example shows you how to use equals method.
Here is the code.
/**
* @(#) EqualsShort.java
* A class representing use of method equals() of Short class in java.lang Package.
* @Version 03-May-2008
* @author Rose India Team
*/
class EqualsShort{
public static void main(String[] args){
short shortNum1 = 123, shortNum2 = 321, shortNum3 = 123;
Short ShortObj1 = new Short(shortNum1);
Short ShortObj2 = new Short(shortNum2);
Short ShortObj3 = new Short(shortNum3);
//Method returns true if and only if the argument contains the same short value as this object.
boolean bool = ShortObj1.equals(ShortObj3);
System.out.println("Is both object have same short value ? " + bool);
//Method returns false if the argument contains different short value as this object.
bool = ShortObj1.equals(ShortObj2);
System.out.println("Is both object have same short value ? " + bool);
}
} |
|