Compare two short values
int compareTo(Short anotherShort)
- Compares two Short objects numerically.
boolean equals(Object obj)
- Compares this object to the specified object.
compareTo(Short anotherShort) compares two Short objects numerically. It returns
Value Returned | Meaning |
---|---|
0 | if this Short is equal to the argument Short; |
< 0 | if this Short is numerically less than the argument Short; and |
> 0 | if this Short is numerically greater than the argument Short. |
public class Main {
public static void main(String[] args) {
Short shortValue1 = new Short("10");
Short shortValue2 = new Short("11");
System.out.println(shortValue1.compareTo(shortValue2));
}
}
The output:
-1
public class Main {
public static void main(String[] args) {
Short shortValue1 = new Short("10");
Short shortValue2 = new Short("11");
System.out.println(shortValue1.equals(shortValue2));
}
}
The output:
false
Home
Java Book
Essential Classes
Java Book
Essential Classes
Short:
- Short class
- Find out the min value, max value and size of Short types
- Create Short object with its constructor
- Convert Short to byte, double, float, int, long and short
- Decode a string to short value
- Convert string to a short value
- Reverse the bytes in a short
- Convert short value to string
- Compare two short values