Final

java.lang
Class Integer

java.lang.Object
  extended by java.lang.Number
      extended by java.lang.Integer
All Implemented Interfaces:
Serializable, Comparable<Integer>

public final class Integer
extends Number
implements Comparable<Integer>

Integers are objects (non-base types) which represent int values.

See Also:
Serialized Form

Field Summary
static int MAX_VALUE
          Most positive possible int value.
static int MIN_VALUE
          Most negative possible int value.
static int SIZE
          The size in bits of this base-type (32).
static Class<Integer> TYPE
          The java.lang.Class that represents this class.
 
Constructor Summary
Integer(int value)
          Constructs a new instance of the receiver which represents the int valued argument.
Integer(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(Integer object)
          Answers an integer indicating the relative positions of the receiver and the argument in the natural order of elements.
static Integer decode(String string)
          Parses the string argument as if it was an int value and returns the result.
 double doubleValue()
          Answers the double value which the receiver represents
 boolean equals(Object o)
          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
static Integer getInteger(String string)
          Answers an Integer representing the integer value of the property named by the argument.
static Integer getInteger(String string, int defaultValue)
          Answers an Integer representing the integer value of the property named by the argument.
static Integer getInteger(String string, Integer defaultValue)
          Answers an Integer representing the integer value of the property named by the argument.
 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 int parseInt(String string)
          Parses the string argument as if it was an int value and returns the result.
static int parseInt(String string, int radix)
          Parses the string argument as if it was an int value and returns the result.
 short shortValue()
          Answers the short value which the receiver represents
static String toBinaryString(int i)
          Answers a string containing '0' and '1' characters which describe the binary representation of the argument.
static String toHexString(int i)
          Answers a string containing characters in the range 0..9, a..f which describe the hexadecimal representation of the argument.
static String toOctalString(int i)
          Answers a string containing characters in the range 0..7 which describe the octal representation of the argument.
 String toString()
          Answers a string containing a concise, human-readable description of the receiver.
static String toString(int i)
          Answers a string containing characters in the range 0..9 which describe the decimal representation of the argument.
static String toString(int i, int radix)
          Answers a string containing characters in the range 0..9, a..z (depending on the radix) which describe the representation of the argument in that radix.
static Integer valueOf(int value)
          Constructs a new instance of the receiver which represents the given base-type value.
static Integer valueOf(String string)
          Parses the string argument as if it was an int value and returns the result.
static Integer valueOf(String string, int radix)
          Parses the string argument as if it was an int value and returns the result.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final int MAX_VALUE
Most positive possible int value.

See Also:
Constant Field Values

MIN_VALUE

public static final int MIN_VALUE
Most negative possible int value.

See Also:
Constant Field Values

SIZE

public static final int SIZE
The size in bits of this base-type (32).

See Also:
Constant Field Values

TYPE

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

Constructor Detail

Integer

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

Parameters:
value - the int to store in the new instance.

Integer

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

Parameters:
string - a string representation of an int quantity.
Throws:
NumberFormatException - if the argument could not be parsed as an int quantity.
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(Integer object)
Answers an integer indicating the relative positions of the receiver and the argument in the natural order of elements.

Specified by:
compareTo in interface Comparable<Integer>
Parameters:
object - an Integer 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.

decode

public static Integer decode(String string)
                      throws NumberFormatException
Parses the string argument as if it was an int 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 an integer

Parameters:
string - a string representation of an int quantity.
Returns:
Integer the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as an int 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 o)
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 an Integer, and the receiver and argument must represent the same int value.

Overrides:
equals in class Object
Parameters:
o - 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.

getInteger

public static Integer getInteger(String string)
Answers an Integer representing the integer value of the property named by the argument. If the property could not be found, or its value could not be parsed as an integer, answer null.

Parameters:
string - The name of the desired integer property.
Returns:
Integer An Integer representing the value of the property.

getInteger

public static Integer getInteger(String string,
                                 int defaultValue)
Answers an Integer representing the integer value of the property named by the argument. If the property could not be found, or its value could not be parsed as an integer, answer an Integer reperesenting the second argument.

Parameters:
string - The name of the desired integer property.
defaultValue - The default Integer value to return if the propery could not be found, or the property value could not be parsed
Returns:
Integer An Integer representing the value of the property, or the defaultValue

getInteger

public static Integer getInteger(String string,
                                 Integer defaultValue)
Answers an Integer representing the integer value of the property named by the argument. If the property could not be found, or its value could not be parsed as an integer, answer the second argument.

Parameters:
string - The name of the desired integer property.
defaultValue - The default Integer to return if the propery could not be found, or the property value could not be parsed
Returns:
Integer An Integer representing the value of the property, or the defaultValue

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.

parseInt

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

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

parseInt

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

Parameters:
string - a string representation of an int quantity.
radix - the base to use for conversion.
Returns:
int the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as an int 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.

toBinaryString

public static String toBinaryString(int i)
Answers a string containing '0' and '1' characters which describe the binary representation of the argument.

Parameters:
i - an int to get the binary representation of
Returns:
String the binary representation of the argument

toHexString

public static String toHexString(int i)
Answers a string containing characters in the range 0..9, a..f which describe the hexadecimal representation of the argument.

Parameters:
i - an int to get the hex representation of
Returns:
String the hex representation of the argument

toOctalString

public static String toOctalString(int i)
Answers a string containing characters in the range 0..7 which describe the octal representation of the argument.

Parameters:
i - an int to get the octal representation of
Returns:
String the hex representation of the argument

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(int i)
Answers a string containing characters in the range 0..9 which describe the decimal representation of the argument.

Parameters:
i - an int to get the representation of
Returns:
String the representation of the argument

toString

public static String toString(int i,
                              int radix)
Answers a string containing characters in the range 0..9, a..z (depending on the radix) which describe the representation of the argument in that radix.

Parameters:
i - an int to get the representation of
radix - the base to use for conversion.
Returns:
String the representation of the argument

valueOf

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

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

valueOf

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

Parameters:
string - a string representation of an int quantity.
radix - the base to use for conversion.
Returns:
Integer the value represented by the argument
Throws:
NumberFormatException - if the argument could not be parsed as an int quantity.

valueOf

public static Integer valueOf(int value)
Constructs a new instance of the receiver which represents the given base-type value.

In contrast to the constructor Integer(int) this method provides space and performance benefits by caching frequently used values.

Parameters:
value - the base-byte to store in the new instance
Returns:
an instance of the receiving class

Final

Licensed Materials - Property of IBM
© Copyright IBM Corp. 2006, 2008 All Rights Reserved.