Package java.lang
Class Short
- java.lang.Object
-
- java.lang.Number
-
- java.lang.Short
-
- All Implemented Interfaces:
Serializable,Comparable<Short>,Modified
public final class Short extends Number implements Comparable<Short>, Modified
The wrapper for the primitive typeshort.- Since:
- 1.1
- See Also:
Number, Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description bytebyteValue()Returns this object's value as a byte.static intcompare(short lhs, short rhs)Compares twoshortvalues.intcompareTo(Short object)Compares this object to the specified short object to determine their relative order.static Shortdecode(String string)Parses the specified string and returns aShortinstance if the string can be decoded into a short value.doubledoubleValue()Returns this object's value as a double.booleanequals(Object object)Compares this instance with the specified object and indicates if they are equal.floatfloatValue()Returns this object's value as a float.inthashCode()Returns an integer hash code for this object.intintValue()Returns this object's value as an int.longlongValue()Returns this object's value as a long.static shortparseShort(String string)Parses the specified string as a signed decimal short value.static shortparseShort(String string, int radix)Parses the specified string as a signed short value using the specified radix.static shortreverseBytes(short s)Reverses the bytes of the specified short.shortshortValue()Gets the primitive value of this short.StringtoString()Returns a string containing a concise, human-readable description of this object.static StringtoString(short value)Returns a string containing a concise, human-readable description of the specified short value with radix 10.static ShortvalueOf(short s)Returns aShortinstance for the specified short value.static ShortvalueOf(String string)Parses the specified string as a signed decimal short value.static ShortvalueOf(String string, int radix)Parses the specified string as a signed short value using the specified radix.
-
-
-
Field Detail
-
MAX_VALUE
public static final short MAX_VALUE
Constant for the maximumshortvalue, 215-1.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final short MIN_VALUE
Constant for the minimumshortvalue, -215.- See Also:
- Constant Field Values
-
SIZE
public static final int SIZE
Constant for the number of bits needed to represent ashortin two's complement form.- Since:
- 1.5
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Short
public Short(String string) throws NumberFormatException
Constructs a newShortfrom the specified string.- Parameters:
string- the string representation of a short value.- Throws:
NumberFormatException- ifstringcannot be parsed as a short value.- See Also:
parseShort(String)
-
Short
public Short(short value)
Constructs a newShortwith the specified primitive short value.- Parameters:
value- the primitive short value to store in the new instance.
-
-
Method Detail
-
byteValue
public byte byteValue()
Description copied from class:NumberReturns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.
-
compareTo
public int compareTo(Short object)
Compares this object to the specified short object to determine their relative order.- Specified by:
compareToin interfaceComparable<Short>- Parameters:
object- the short object to compare this object to.- Returns:
- a negative value if the value of this short is less than the
value of
object; 0 if the value of this short and the value ofobjectare equal; a positive value if the value of this short is greater than the value ofobject. - Throws:
NullPointerException- ifobjectis null.- Since:
- 1.2
- See Also:
Comparable
-
compare
public static int compare(short lhs, short rhs)Compares twoshortvalues.- Parameters:
lhs- First value.rhs- Second value.- Returns:
- 0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs.
- Since:
- 1.7
-
decode
public static Short decode(String string) throws NumberFormatException
Parses the specified string and returns aShortinstance if the string can be decoded into a short value. The string may be an optional minus sign "-" followed by a hexadecimal ("0x..." or "#..."), octal ("0..."), or decimal ("...") representation of a short.- Parameters:
string- a string representation of a short value.- Returns:
- a
Shortcontaining the value represented bystring. - Throws:
NumberFormatException- ifstringcannot be parsed as a short value.
-
doubleValue
public double doubleValue()
Description copied from class:NumberReturns this object's value as a double. Might involve rounding.- Specified by:
doubleValuein classNumber- Returns:
- the primitive double value of this object.
-
equals
public boolean equals(Object object)
Compares this instance with the specified object and indicates if they are equal. In order to be equal,objectmust be an instance ofShortand have the same short value as this object.- Overrides:
equalsin classObject- Parameters:
object- the object to compare this short with.- Returns:
trueif the specified object is equal to thisShort;falseotherwise.- See Also:
Object.hashCode()
-
floatValue
public float floatValue()
Description copied from class:NumberReturns this object's value as a float. Might involve rounding.- Specified by:
floatValuein classNumber- Returns:
- the primitive float value of this object.
-
hashCode
public int hashCode()
Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually override both methods or neither method.Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
intValue
public int intValue()
Description copied from class:NumberReturns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.
-
longValue
public long longValue()
Description copied from class:NumberReturns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.
-
parseShort
public static short parseShort(String string) throws NumberFormatException
Parses the specified string as a signed decimal short value. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string- the string representation of a short value.- Returns:
- the primitive short value represented by
string. - Throws:
NumberFormatException- ifstringcannot be parsed as a short value.
-
parseShort
public static short parseShort(String string, int radix) throws NumberFormatException
Parses the specified string as a signed short value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string- the string representation of a short value.radix- the radix to use when parsing.- Returns:
- the primitive short value represented by
stringusingradix. - Throws:
NumberFormatException- ifstringcannot be parsed as a short value, orradix < Character.MIN_RADIX || radix > Character.MAX_RADIX.
-
shortValue
public short shortValue()
Gets the primitive value of this short.- Overrides:
shortValuein classNumber- Returns:
- this object's primitive value.
-
toString
public String toString()
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data.
-
toString
public static String toString(short value)
Returns a string containing a concise, human-readable description of the specified short value with radix 10.- Parameters:
value- the short to convert to a string.- Returns:
- a printable representation of
value.
-
valueOf
public static Short valueOf(String string) throws NumberFormatException
Parses the specified string as a signed decimal short value.- Parameters:
string- the string representation of a short value.- Returns:
- a
Shortinstance containing the short value represented bystring. - Throws:
NumberFormatException- ifstringcannot be parsed as a short value.- See Also:
parseShort(String)
-
valueOf
public static Short valueOf(String string, int radix) throws NumberFormatException
Parses the specified string as a signed short value using the specified radix.- Parameters:
string- the string representation of a short value.radix- the radix to use when parsing.- Returns:
- a
Shortinstance containing the short value represented bystringusingradix. - Throws:
NumberFormatException- ifstringcannot be parsed as a short value, orradix < Character.MIN_RADIX || radix > Character.MAX_RADIX.- See Also:
parseShort(String, int)
-
reverseBytes
public static short reverseBytes(short s)
Reverses the bytes of the specified short.- Parameters:
s- the short value for which to reverse bytes.- Returns:
- the reversed value.
- Since:
- 1.5
-
valueOf
public static Short valueOf(short s)
Returns aShortinstance for the specified short value.If it is not necessary to get a new
Shortinstance, it is recommended to use this method instead of the constructor, since it maintains a cache of instances which may result in better performance.- Parameters:
s- the short value to store in the instance.- Returns:
- a
Shortinstance containings. - Since:
- 1.5
-
-