FileDocCategorySizeDatePackage
Short.javaAPI DocAndroid 1.5 API11065Wed May 06 22:41:04 BST 2009java.lang

Short

public final class Short extends Number implements Comparable
The wrapper for the primitive type {@code short}.
see
java.lang.Number
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private final short
value
The value which the receiver represents.
public static final short
MAX_VALUE
Constant for the maximum {@code short} value, 215-1.
public static final short
MIN_VALUE
Constant for the minimum {@code short} value, -215.
public static final int
SIZE
Constant for the number of bits needed to represent a {@code short} in two's complement form.
public static final Class
TYPE
The {@link Class} object that represents the primitive type {@code short}.
Constructors Summary
public Short(String string)
Constructs a new {@code Short} from the specified string.

param
string the string representation of a short value.
throws
NumberFormatException if {@code string} can not be decoded into a short value.
see
#parseShort(String)
since
Android 1.0


    // Note: This can't be set to "short.class", since *that* is
    // defined to be "java.lang.Short.TYPE";

    
                                                                     
         
        this(parseShort(string));
    
public Short(short value)
Constructs a new {@code Short} with the specified primitive short value.

param
value the primitive short value to store in the new instance.
since
Android 1.0

        this.value = value;
    
Methods Summary
public bytebyteValue()

        return (byte) value;
    
public intcompareTo(java.lang.Short object)
Compares this object to the specified short object to determine their relative order.

param
object the short object to compare this object to.
return
a negative value if the value of this short is less than the value of {@code object}; 0 if the value of this short and the value of {@code object} are equal; a positive value if the value of this short is greater than the value of {@code object}.
see
java.lang.Comparable
since
Android 1.0

        return value > object.value ? 1 : (value < object.value ? -1 : 0);
    
public static java.lang.Shortdecode(java.lang.String string)
Parses the specified string and returns a {@code Short} instance 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.

param
string a string representation of a short value.
return
a {@code Short} containing the value represented by {@code string}.
throws
NumberFormatException if {@code string} can not be parsed as a short value.
since
Android 1.0

        int intValue = Integer.decode(string).intValue();
        short result = (short) intValue;
        if (result == intValue) {
            return valueOf(result);
        }
        throw new NumberFormatException();
    
public doubledoubleValue()

        return value;
    
public booleanequals(java.lang.Object object)
Compares this instance with the specified object and indicates if they are equal. In order to be equal, {@code object} must be an instance of {@code Short} and have the same short value as this object.

param
object the object to compare this short with.
return
{@code true} if the specified object is equal to this {@code Short}; {@code false} otherwise.
since
Android 1.0

        return (object instanceof Short)
                && (value == ((Short) object).value);
    
public floatfloatValue()

        return value;
    
public inthashCode()

        return value;
    
public intintValue()

        return value;
    
public longlongValue()

        return value;
    
public static shortparseShort(java.lang.String string)
Parses the specified string as a signed decimal short value. The ASCII character \u002d ('-') is recognized as the minus sign.

param
string the string representation of a short value.
return
the primitive short value represented by {@code string}.
throws
NumberFormatException if {@code string} is {@code null}, has a length of zero or can not be parsed as a short value.
since
Android 1.0

        return parseShort(string, 10);
    
public static shortparseShort(java.lang.String string, int radix)
Parses the specified string as a signed short value using the specified radix. The ASCII character \u002d ('-') is recognized as the minus sign.

param
string the string representation of a short value.
param
radix the radix to use when parsing.
return
the primitive short value represented by {@code string} using {@code radix}.
throws
NumberFormatException if {@code string} is {@code null} or has a length of zero, {@code radix < Character.MIN_RADIX}, {@code radix > Character.MAX_RADIX}, or if {@code string} can not be parsed as a short value.
since
Android 1.0

        int intValue = Integer.parseInt(string, radix);
        short result = (short) intValue;
        if (result == intValue) {
            return result;
        }
        throw new NumberFormatException();
    
public static shortreverseBytes(short s)
Reverses the bytes of the specified short.

param
s the short value for which to reverse bytes.
return
the reversed value.
since
Android 1.0

        int high = (s >> 8) & 0xFF;
        int low = (s & 0xFF) << 8;
        return (short) (low | high);
    
public shortshortValue()
Gets the primitive value of this short.

return
this object's primitive value.
since
Android 1.0

        return value;
    
public java.lang.StringtoString()

        return Integer.toString(value);
    
public static java.lang.StringtoString(short value)
Returns a string containing a concise, human-readable description of the specified short value with radix 10.

param
value the short to convert to a string.
return
a printable representation of {@code value}.
since
Android 1.0

        return Integer.toString(value);
    
public static java.lang.ShortvalueOf(java.lang.String string)
Parses the specified string as a signed decimal short value.

param
string the string representation of a short value.
return
a {@code Short} instance containing the short value represented by {@code string}.
throws
NumberFormatException if {@code string} is {@code null}, has a length of zero or can not be parsed as a short value.
see
#parseShort(String)
since
Android 1.0

        return valueOf(parseShort(string));
    
public static java.lang.ShortvalueOf(java.lang.String string, int radix)
Parses the specified string as a signed short value using the specified radix.

param
string the string representation of a short value.
param
radix the radix to use when parsing.
return
a {@code Short} instance containing the short value represented by {@code string} using {@code radix}.
throws
NumberFormatException if {@code string} is {@code null} or has a length of zero, {@code radix < Character.MIN_RADIX}, {@code radix > Character.MAX_RADIX}, or if {@code string} can not be parsed as a short value.
see
#parseShort(String, int)
since
Android 1.0

        return valueOf(parseShort(string, radix));
    
public static java.lang.ShortvalueOf(short s)
Returns a {@code Short} instance for the specified short value.

If it is not necessary to get a new {@code Short} instance, it is recommended to use this method instead of the constructor, since it maintains a cache of instances which may result in better performance.

param
s the short value to store in the instance.
return
a {@code Short} instance containing {@code s}.
since
Android 1.0

        if (s < -128 || s > 127) {
            return new Short(s);
        }
        return valueOfCache.CACHE[s+128];