Final

java.lang
Class Short

java.lang.Object
  extended byjava.lang.Number
      extended byjava.lang.Short
All Implemented Interfaces:
Comparable, Serializable

public final class Short
extends Number
implements Comparable

Shorts are objects (non-base types) which represent short values.

See Also:
Serialized Form

Field Summary
static short MAX_VALUE
          Most positive and most negative possible short values.
static short MIN_VALUE
           
static Class TYPE
          The java.lang.Class that represents this class.
 
Constructor Summary
Short(short value)
          Constructs a new instance of the receiver which represents the short valued argument.
Short(String string)
          Constructs a new instance of this class given a string.
 
Method Summary
 byte byteValue()
          Answers the byte value which the receiver represents
 int compareTo(Object object)
          Answers an integer indicating the relative positions of the receiver and the argument in the natural order of elements of the receiver's class.
 int compareTo(Short object)
           
static Short decode(String string)
          Parses the string argument as if it was a short value and returns the result.
 double doubleValue()
          Answers the double value which the receiver represents
 boolean equals(Object object)
          Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
 float floatValue()
          Answers the float value which the receiver represents
 int hashCode()
          Answers an integer hash code for the receiver.
 int intValue()
          Answers the int value which the receiver represents
 long longValue()
          Answers the long value which the receiver represents
static short parseShort(String string)
          Parses the string argument as if it was a short value and returns the result.
static short parseShort(String string, int radix)
          Parses the string argument as if it was a short value and returns the result.
 short shortValue()
          Answers the short value which the receiver represents
 String toString()
          Answers a string containing a concise, human-readable description of the receiver.
static String toString(short value)
          Answers a string containing a concise, human-readable description of the argument.
static Short valueOf(String string)
          Parses the string argument as if it was a short value and returns a Short representing the result.
static Short valueOf(String string, int radix)
          Parses the string argument as if it was a short value and returns a Short representing the result.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final short MAX_VALUE
Most positive and most negative possible short values.

See Also:
Constant Field Values

MIN_VALUE

public static final short MIN_VALUE
See Also:
Constant Field Values

TYPE

public static final Class TYPE
The java.lang.Class that represents this class.

Constructor Detail

Short

public Short(String string)
      throws NumberFormatException
Constructs a new instance of this class given a string.

Parameters:
string - a string representation of a short quantity.
Throws:
NumberFormatException - if the argument could not be parsed as a short quantity.

Short

public Short(short value)
Constructs a new instance of the receiver which represents the short valued argument.

Parameters:
value - the short to store in the new instance.
Method Detail

byteValue

public byte byteValue()
Answers the byte value which the receiver represents

Overrides:
byteValue in class Number
Returns:
byte the value of the receiver.

compareTo

public int compareTo(Object object)
Description copied from interface: Comparable
Answers an integer indicating the relative positions of the receiver and the argument in the natural order of elements of the receiver's class.

Specified by:
compareTo in interface Comparable
Parameters:
object - Object an object to compare the receiver to
Returns:
int which should be <0 if the receiver should sort before the argument, 0 if the receiver should sort in the same position as the argument, and >0 if the receiver should sort after the argument.

compareTo

public int compareTo(Short object)

decode

public static Short decode(String string)
                    throws NumberFormatException
Parses the string argument as if it was a short value and returns the result. Throws NumberFormatException if the string does not represent an int quantity. The string may be a hexadecimal ("0x..."), octal ("0..."), or decimal ("...") representation of a byte.

Parameters:
string - a string representation of a short quantity.
Returns:
Short the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as a short quantity.

doubleValue

public double doubleValue()
Answers the double value which the receiver represents

Specified by:
doubleValue in class Number
Returns:
double the value of the receiver.

equals

public boolean equals(Object object)
Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.

In this case, the argument must also be a Short, and the receiver and argument must represent the same short value.

Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the object is the same as this object false if it is different from this object
See Also:
hashCode()

floatValue

public float floatValue()
Answers the float value which the receiver represents

Specified by:
floatValue in class Number
Returns:
float the value of the receiver.

hashCode

public int hashCode()
Answers an integer hash code for the receiver. Any two objects which answer true when passed to equals must answer the same value for this method.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

intValue

public int intValue()
Answers the int value which the receiver represents

Specified by:
intValue in class Number
Returns:
int the value of the receiver.

longValue

public long longValue()
Answers the long value which the receiver represents

Specified by:
longValue in class Number
Returns:
long the value of the receiver.

parseShort

public static short parseShort(String string)
                        throws NumberFormatException
Parses the string argument as if it was a short value and returns the result. Throws NumberFormatException if the string does not represent an short quantity.

Parameters:
string - a string representation of a short quantity.
Returns:
short the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as a short quantity.

parseShort

public static short parseShort(String string,
                               int radix)
                        throws NumberFormatException
Parses the string argument as if it was a short value and returns the result. Throws NumberFormatException if the string does not represent a single short quantity. The second argument specifies the radix to use when parsing the value.

Parameters:
string - a string representation of a short quantity.
radix - the radix to use when parsing.
Returns:
short the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as a short quantity.

shortValue

public short shortValue()
Answers the short value which the receiver represents

Overrides:
shortValue in class Number
Returns:
short the value of the receiver.

toString

public String toString()
Answers a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
a printable representation for the receiver.

toString

public static String toString(short value)
Answers a string containing a concise, human-readable description of the argument.

Parameters:
value - short the short to convert.
Returns:
String a printable representation for the short.

valueOf

public static Short valueOf(String string)
                     throws NumberFormatException
Parses the string argument as if it was a short value and returns a Short representing the result. Throws NumberFormatException if the string does not represent a single short quantity.

Parameters:
string - a string representation of a short quantity.
Returns:
Short the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as a short quantity.

valueOf

public static Short valueOf(String string,
                            int radix)
                     throws NumberFormatException
Parses the string argument as if it was a short value and returns a Short representing the result. Throws NumberFormatException if the string does not represent a short quantity. The second argument specifies the radix to use when parsing the value.

Parameters:
string - a string representation of a short quantity.
radix - the radix to use when parsing.
Returns:
Short the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as a short quantity.

Final

Licensed Materials - Property of IBM
(C) Copyright IBM Corp. 2006 All Rights Reserved.