java.lang
Class Short

java.lang.Object
  |
  +--java.lang.Number
        |
        +--java.lang.Short

public final class Short
extends Number
implements Comparable

The Short class is the standard wrapper for short values.

Since:
JDK1.1
See Also:
Number, Serialized Form

Field Summary
static short MAX_VALUE
          The maximum value a Short can have.
static short MIN_VALUE
          The minimum value a Short can have.
private static long serialVersionUID
          use serialVersionUID from JDK 1.1.
static Class TYPE
          The Class object representing the primitive type short.
private  short value
          The value of the Short.
 
Fields inherited from class java.lang.Number
serialVersionUID
 
Constructor Summary
Short(short value)
          Constructs a Short object initialized to the specified short value.
Short(String s)
          Constructs a Short object initialized to the value specified by the String parameter.
 
Method Summary
 byte byteValue()
          Returns the value of this Short as a byte.
 int compareTo(Object o)
          Compares this Short to another Object.
 int compareTo(Short anotherShort)
          Compares two Shorts numerically.
static Short decode(String nm)
          Decodes a String into a Short.
 double doubleValue()
          Returns the value of this Short as a double.
 boolean equals(Object obj)
          Compares this object to the specified object.
 float floatValue()
          Returns the value of this Short as a float.
 int hashCode()
          Returns a hashcode for this Short.
 int intValue()
          Returns the value of this Short as an int.
 long longValue()
          Returns the value of this Short as a long.
static short parseShort(String s)
          Assuming the specified String represents a short, returns that short's value.
static short parseShort(String s, int radix)
          Assuming the specified String represents a short, returns that short's value.
 short shortValue()
          Returns the value of this Short as a short.
 String toString()
          Returns a String object representing this Short's value.
static String toString(short s)
          Returns a new String object representing the specified Short.
static Short valueOf(String s)
          Assuming the specified String represents a short, returns a new Short object initialized to that value.
static Short valueOf(String s, int radix)
          Assuming the specified String represents a short, returns a new Short object initialized to that value.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final short MIN_VALUE
The minimum value a Short can have.

MAX_VALUE

public static final short MAX_VALUE
The maximum value a Short can have.

TYPE

public static final Class TYPE
The Class object representing the primitive type short.

value

private short value
The value of the Short.

serialVersionUID

private static final long serialVersionUID
use serialVersionUID from JDK 1.1. for interoperability
Constructor Detail

Short

public Short(short value)
Constructs a Short object initialized to the specified short value.
Parameters:
value - the initial value of the Short

Short

public Short(String s)
      throws NumberFormatException
Constructs a Short object initialized to the value specified by the String parameter. The radix is assumed to be 10.
Parameters:
s - the String to be converted to a Short
Throws:
NumberFormatException - If the String does not contain a parsable short.
Method Detail

toString

public static String toString(short s)
Returns a new String object representing the specified Short. The radix is assumed to be 10.
Parameters:
s - the short to be converted

parseShort

public static short parseShort(String s)
                        throws NumberFormatException
Assuming the specified String represents a short, returns that short's value. Throws an exception if the String cannot be parsed as a short. The radix is assumed to be 10.
Parameters:
s - the String containing the short
Throws:
NumberFormatException - If the string does not contain a parsable short.

parseShort

public static short parseShort(String s,
                               int radix)
                        throws NumberFormatException
Assuming the specified String represents a short, returns that short's value. Throws an exception if the String cannot be parsed as a short.
Parameters:
s - the String containing the short
radix - the radix to be used
Throws:
NumberFormatException - If the String does not contain a parsable short.

valueOf

public static Short valueOf(String s,
                            int radix)
                     throws NumberFormatException
Assuming the specified String represents a short, returns a new Short object initialized to that value. Throws an exception if the String cannot be parsed as a short.
Parameters:
s - the String containing the integer
radix - the radix to be used
Throws:
NumberFormatException - If the String does not contain a parsable short.

valueOf

public static Short valueOf(String s)
                     throws NumberFormatException
Assuming the specified String represents a short, returns a new Short object initialized to that value. Throws an exception if the String cannot be parsed as a short.
Parameters:
s - the String containing the integer
Throws:
NumberFormatException - If the String does not contain a parsable short.

decode

public static Short decode(String nm)
                    throws NumberFormatException
Decodes a String into a Short. Accepts decimal, hexadecimal, and octal numbers, in the following formats:
     [-]    
     [-] 0x     
     [-] #      
     [-] 0    
 
The constant following an (optional) negative sign and/or "radix specifier" is parsed as by the Short.parseShort method with the specified radix (10, 8 or 16). This constant must be positive or a NumberFormatException will result. The result is made negative if first character of the specified String is the negative sign. No whitespace characters are permitted in the String.
Parameters:
nm - the String to decode.
Returns:
the Short represented by the specified string.
Throws:
NumberFormatException - if the String does not contain a parsable short.
See Also:
parseShort(String, int)

byteValue

public byte byteValue()
Returns the value of this Short as a byte.
Overrides:
byteValue in class Number

shortValue

public short shortValue()
Returns the value of this Short as a short.
Overrides:
shortValue in class Number

intValue

public int intValue()
Returns the value of this Short as an int.
Overrides:
intValue in class Number

longValue

public long longValue()
Returns the value of this Short as a long.
Overrides:
longValue in class Number

floatValue

public float floatValue()
Returns the value of this Short as a float.
Overrides:
floatValue in class Number

doubleValue

public double doubleValue()
Returns the value of this Short as a double.
Overrides:
doubleValue in class Number

toString

public String toString()
Returns a String object representing this Short's value.
Overrides:
toString in class Object

hashCode

public int hashCode()
Returns a hashcode for this Short.
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Compares this object to the specified object.
Parameters:
obj - the object to compare with
Returns:
true if the objects are the same; false otherwise.
Overrides:
equals in class Object

compareTo

public int compareTo(Short anotherShort)
Compares two Shorts numerically.
Parameters:
anotherShort - the Short to be compared.
Returns:
the value 0 if the argument Short is equal to this Short; a value less than 0 if this Short is numerically less than the Short argument; and a value greater than 0 if this Short is numerically greater than the Short argument (signed comparison).
Since:
JDK1.2

compareTo

public int compareTo(Object o)
Compares this Short to another Object. If the Object is a Short, this function behaves like compareTo(Short). Otherwise, it throws a ClassCastException (as Shorts are comparable only to other Shorts).
Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is a Short numerically equal to this Short; a value less than 0 if the argument is a Short numerically greater than this Short; and a value greater than 0 if the argument is a Short numerically less than this Short.
Throws:
ClassCastException - if the argument is not a Short.
Since:
JDK1.2
See Also:
Comparable