Java Short Class
The short class wraps a primitive short type value in an object. Its object contains only a single field whose type is short.
Methods:
The java.lang.Short class provides several different methods for converting a short to a String or vice versa. This class also provides other constants and methods which are useful when we are dealing with short.
Methods |
Description |
byteValue() |
It returns the value of this Short as a short |
compare() |
It compares the two specified short values |
compareTo() |
It compares two Short objects numerically |
compareUnsigned() |
It compares the two unsigned short values |
decode() |
It is used to decode a String into a Short |
doubleValue() |
It returns a double value for this Short object |
equals() |
It is used to compare this object against the specified short object |
floatValue() |
It returns the value of this Short as a Float |
hashCode() |
It returns a hash code for this Short object |
intValue() |
It returns an int value for this Short object |
longValue() |
It returns a long value for this Short object |
parseShort() |
It is used to parse the string argument as a signed decimal short. |
reverseBytes() |
It returns the value fetched by reversing the order of the bytes in 2's complement representation of the given short value. |
shortValue() |
It returns a short value for this Short object |
toString() |
This method returns a string representation for the Short's object |
toUnsignedInt() |
It is used to convert the specified short to an int by an unsigned conversion |
toUnsignedLong() |
It is used to convert the specified short to a long by an unsigned conversion |
valueOf() |
Returns a Short instance representing the specified short or string value. |
Example 1
Test it Now
Output:
1. 500 is greater than 12
2. 12 and 12 are equal.
3. Long value of 12 is : 12
4. String value of 12 is : 12
5. Double value of 500 is : 500.0
Example 2
Test it Now
Output:
1. 607 is greater than 50
2. Hash code value of 50 is : 50
3. Float value of 607 is : 607.0
4. Integer value of 607 is : 607
5. Decoded value of string value 123 is : 123
|