![]() |
VOOZH | about |
Short class is a wrapper class for the primitive type short which contains several methods to effectively deal with a short value like converting it to a string representation, and vice-versa. An object of Short class can hold a single short value. There are mainly two constructors to initialize a Short object-
Syntax : public Short(short b) Parameters : b : value with which to initialize
Syntax : public Short(String s) throws NumberFormatException Parameters : s : string representation of the short value Throws : NumberFormatException : If the string provided does not represent any short value.
Methods:
Syntax : public String toString(short b) Parameters : b : short value for which string representation required.
Syntax : public static Short valueOf(short b) Parameters : b : a short value
Syntax : public static Short valueOf(String val, int radix) throws NumberFormatException Parameters : val : String to be parsed into short value radix : radix to be used while parsing Throws : NumberFormatException : if String cannot be parsed to a short value in given radix.
Syntax : public static Short valueOf(String s) throws NumberFormatException Parameters : s : a String object to be parsed as short Throws : NumberFormatException : if String cannot be parsed to a short value in given radix.
Syntax : public static short parseShort(String val, int radix) throws NumberFormatException Parameters : val : String representation of short radix : radix to be used while parsing Throws : NumberFormatException : if String cannot be parsed to a short value in given radix.
Syntax : public static short parseShort(String val) throws NumberFormatException Parameters : val : String representation of short Throws : NumberFormatException : if String cannot be parsed to a short value in given radix.
Syntax : public static Short decode(String s) throws NumberFormatException Parameters : s : encoded string to be parsed into short val Throws : NumberFormatException : If the string cannot be decoded into a short value
Syntax : public byte byteValue()
Syntax : public short shortValue()
Syntax : public int intValue()
Syntax : public long longValue()
Syntax : public double doubleValue()
Syntax : public float floatValue()
Syntax : public int hashCode()
Syntax : public boolean equals(Object obj) Parameters : obj : object to compare with
Syntax : public int compareTo(Short b) Parameters : b : Short object to compare with
Syntax : public static int compare(short x,short y) Parameters : x : short value y : another short value
Syntax : public static short reverseBytes(short val) Parameters : val : short value whose bits to reverse in order.
Output :
toString(b) = 55 valueOf(b) = 55 ValueOf(bb) = 45 ValueOf(bb,6) = 29 parseShort(bb) = 45 parseShort(bb,6) = 29 decode(45) = 45 decode(005) = 5 decode(0x0f) = 15 bytevalue(x) = 55 shortvalue(x) = 55 intvalue(x) = 55 longvalue(x) = 55 doublevalue(x) = 55.0 floatvalue(x) = 55.0 hashcode(x) = 55 x.equals(y) = false compare(x,y) = 10 x.compareTo(y) = 10 Short.reverseBytes(to_rev) = 11520