Save This Page
Home » openjdk-7 » java » lang » [javadoc | source]
java.lang
public final class: Short [javadoc | source]
java.lang.Object
   java.lang.Number
      java.lang.Short

All Implemented Interfaces:
    Comparable, Serializable

The {@code Short} class wraps a value of primitive type {@code short} in an object. An object of type {@code Short} contains a single field whose type is {@code short}.

In addition, this class provides several methods for converting a {@code short} to a {@code String} and a {@code String} to a {@code short}, as well as other constants and methods useful when dealing with a {@code short}.

Field Summary
public static final  short MIN_VALUE    A constant holding the minimum value a {@code short} can have, -215
public static final  short MAX_VALUE    A constant holding the maximum value a {@code short} can have, 215-1. 
public static final  Class TYPE    The {@code Class} instance representing the primitive type {@code short}. 
public static final  int SIZE    The number of bits used to represent a {@code short} value in two's complement binary form.
    since: 1.5 -
 
Constructor:
 public Short(short value) 
 public Short(String s) throws NumberFormatException 
    Constructs a newly allocated {@code Short} object that represents the {@code short} value indicated by the {@code String} parameter. The string is converted to a {@code short} value in exactly the manner used by the {@code parseShort} method for radix 10.
    Parameters:
    s - the {@code String} to be converted to a {@code Short}
    Throws:
    NumberFormatException - If the {@code String} does not contain a parsable {@code short}.
    Also see:
    java.lang.Short#parseShort(java.lang.String, int)
Method from java.lang.Short Summary:
byteValue,   compareTo,   decode,   doubleValue,   equals,   floatValue,   hashCode,   intValue,   longValue,   parseShort,   parseShort,   reverseBytes,   shortValue,   toString,   toString,   valueOf,   valueOf,   valueOf
Methods from java.lang.Number:
byteValue,   doubleValue,   floatValue,   intValue,   longValue,   shortValue
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.lang.Short Detail:
 public byte byteValue() 
    Returns the value of this {@code Short} as a {@code byte}.
 public int compareTo(Short anotherShort) 
    Compares two {@code Short} objects numerically.
 public static Short decode(String nm) throws NumberFormatException 
    Decodes a {@code String} into a {@code Short}. Accepts decimal, hexadecimal, and octal numbers given by the following grammar:
    DecodableString:
    Signopt DecimalNumeral
    Signopt {@code 0x} HexDigits
    Signopt {@code 0X} HexDigits
    Signopt {@code #} HexDigits
    Signopt {@code 0} OctalDigits

    Sign:
    {@code -}
    {@code +}
    DecimalNumeral, HexDigits, and OctalDigits are defined in §3.10.1 of the Java Language Specification.

    The sequence of characters following an optional sign and/or radix specifier ("{@code 0x}", "{@code 0X}", "{@code #}", or leading zero) is parsed as by the {@code Short.parseShort} method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified {@code String} is the minus sign. No whitespace characters are permitted in the {@code String}.

 public double doubleValue() 
    Returns the value of this {@code Short} as a {@code double}.
 public boolean equals(Object obj) 
    Compares this object to the specified object. The result is {@code true} if and only if the argument is not {@code null} and is a {@code Short} object that contains the same {@code short} value as this object.
 public float floatValue() 
    Returns the value of this {@code Short} as a {@code float}.
 public int hashCode() 
    Returns a hash code for this {@code Short}.
 public int intValue() 
    Returns the value of this {@code Short} as an {@code int}.
 public long longValue() 
    Returns the value of this {@code Short} as a {@code long}.
 public static short parseShort(String s) throws NumberFormatException 
    Parses the string argument as a signed decimal {@code short}. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign {@code '-'} ('\u002D') to indicate a negative value or an ASCII plus sign {@code '+'} ('\u002B') to indicate a positive value. The resulting {@code short} value is returned, exactly as if the argument and the radix 10 were given as arguments to the #parseShort(java.lang.String, int) method.
 public static short parseShort(String s,
    int radix) throws NumberFormatException 
    Parses the string argument as a signed {@code short} in the radix specified by the second argument. The characters in the string must all be digits, of the specified radix (as determined by whether java.lang.Character#digit(char, int) returns a nonnegative value) except that the first character may be an ASCII minus sign {@code '-'} ('\u002D') to indicate a negative value or an ASCII plus sign {@code '+'} ('\u002B') to indicate a positive value. The resulting {@code short} value is returned.

    An exception of type {@code NumberFormatException} is thrown if any of the following situations occurs:

    • The first argument is {@code null} or is a string of length zero.
    • The radix is either smaller than java.lang.Character#MIN_RADIX or larger than java.lang.Character#MAX_RADIX .
    • Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign {@code '-'} ('\u002D') or plus sign {@code '+'} ('\u002B') provided that the string is longer than length 1.
    • The value represented by the string is not a value of type {@code short}.
 public static short reverseBytes(short i) 
    Returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified {@code short} value.
 public short shortValue() 
    Returns the value of this {@code Short} as a {@code short}.
 public String toString() 
    Returns a {@code String} object representing this {@code Short}'s value. The value is converted to signed decimal representation and returned as a string, exactly as if the {@code short} value were given as an argument to the java.lang.Short#toString(short) method.
 public static String toString(short s) 
    Returns a new {@code String} object representing the specified {@code short}. The radix is assumed to be 10.
 public static Short valueOf(String s) throws NumberFormatException 
    Returns a {@code Short} object holding the value given by the specified {@code String}. The argument is interpreted as representing a signed decimal {@code short}, exactly as if the argument were given to the #parseShort(java.lang.String) method. The result is a {@code Short} object that represents the {@code short} value specified by the string.

    In other words, this method returns a {@code Short} object equal to the value of:

    {@code new Short(Short.parseShort(s))}
 public static Short valueOf(short s) 
    Returns a {@code Short} instance representing the specified {@code short} value. If a new {@code Short} instance is not required, this method should generally be used in preference to the constructor #Short(short) , as this method is likely to yield significantly better space and time performance by caching frequently requested values.
 public static Short valueOf(String s,
    int radix) throws NumberFormatException 
    Returns a {@code Short} object holding the value extracted from the specified {@code String} when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed {@code short} in the radix specified by the second argument, exactly as if the argument were given to the #parseShort(java.lang.String, int) method. The result is a {@code Short} object that represents the {@code short} value specified by the string.

    In other words, this method returns a {@code Short} object equal to the value of:

    {@code new Short(Short.parseShort(s, radix))}