java.lang
Class Integer

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

public final class Integer
extends Number

The Integer class is a wrapper for integer values. In Java, integers are not objects and most of the Java utility classes require the use of objects. Thus, if you needed to store an integer in a hashtable, you would have to "wrap" an Integer instance around it.


Field Summary
static int MAX_VALUE
          The maximum value an Integer can have.
static int MIN_VALUE
          The minimum value an Integer can have.
 
Constructor Summary
Integer(int value)
          Constructs an Integer object initialized to the specified int value.
Integer(String s)
          Constructs an Integer object initialized to the value specified by the String parameter.
 
Method Summary
 double doubleValue()
          Returns the value of this Integer as a double.
 boolean equals(Object obj)
          Compares this object to the specified object.
 float floatValue()
          Returns the value of this Integer as a float.
static Integer getInteger(String nm)
          Gets an Integer property.
static Integer getInteger(String nm, int val)
          Gets an Integer property.
static Integer getInteger(String nm, Integer val)
          Gets an Integer property.
 int hashCode()
          Returns a hashcode for this Integer.
 int intValue()
          Returns the value of this Integer as an int.
 long longValue()
          Returns the value of this Integer as a long.
static int parseInt(String s)
          Assuming the specified String represents an integer, returns that integer's value.
static int parseInt(String s, int radix)
          Assuming the specified String represents an integer, returns that integer's value.
static String toBinaryString(int i)
          Returns a new String object representing the specified integer as unsigned binary number.
static String toHexString(int i)
          Returns a new String object representing the specified integer as unsigned hexidecimal number.
static String toOctalString(int i)
          Returns a new String object representing the specified integer as unsigned octal number.
 String toString()
          Returns a String object representing this Integer's value.
static String toString(int i)
          Returns a new String object representing the specified integer.
static String toString(int i, int radix)
          Returns a new String object representing the specified integer in the specified radix.
static Integer valueOf(String s)
          Assuming the specified String represents an integer, returns a new Integer object initialized to that value.
static Integer valueOf(String s, int radix)
          Assuming the specified String represents an integer, returns a new Integer object initialized to that value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final int MIN_VALUE
The minimum value an Integer can have. The lowest minimum value an Integer can have is 0x80000000.

See Also:
Constant Field Values

MAX_VALUE

public static final int MAX_VALUE
The maximum value an Integer can have. The greatest maximum value an Integer can have is 0x7fffffff.

See Also:
Constant Field Values
Constructor Detail

Integer

public Integer(int value)
Constructs an Integer object initialized to the specified int value.

Parameters:
value - the initial value of the Integer

Integer

public Integer(String s)
        throws NumberFormatException
Constructs an Integer 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 an Integer
Throws:
NumberFormatException - If the String does not contain a parsable integer.
Method Detail

toString

public static String toString(int i,
                              int radix)
Returns a new String object representing the specified integer in the specified radix.

Parameters:
i - the integer to be converted
radix - the radix
See Also:
Character.MIN_RADIX, Character.MAX_RADIX

toHexString

public static String toHexString(int i)
Returns a new String object representing the specified integer as unsigned hexidecimal number.


toOctalString

public static String toOctalString(int i)
Returns a new String object representing the specified integer as unsigned octal number.


toBinaryString

public static String toBinaryString(int i)
Returns a new String object representing the specified integer as unsigned binary number.


toString

public static String toString(int i)
Returns a new String object representing the specified integer. The radix is assumed to be 10.

Parameters:
i - the integer to be converted

parseInt

public static int parseInt(String s,
                           int radix)
                    throws NumberFormatException
Assuming the specified String represents an integer, returns that integer's value. Throws an exception if the String cannot be parsed as an int.

Parameters:
s - the String containing the integer
radix - the radix to be used
Throws:
NumberFormatException - If the String does not contain a parsable integer.

parseInt

public static int parseInt(String s)
                    throws NumberFormatException
Assuming the specified String represents an integer, returns that integer's value. Throws an exception if the String cannot be parsed as an int. The radix is assumed to be 10.

Parameters:
s - the String containing the integer
Throws:
NumberFormatException - If the string does not contain a parsable integer.

valueOf

public static Integer valueOf(String s,
                              int radix)
                       throws NumberFormatException
Assuming the specified String represents an integer, returns a new Integer object initialized to that value. Throws an exception if the String cannot be parsed as an int.

Parameters:
s - the String containing the integer
radix - the radix to be used
Throws:
NumberFormatException - If the String does not contain a parsable integer.

valueOf

public static Integer valueOf(String s)
                       throws NumberFormatException
Assuming the specified String represents an integer, returns a new Integer object initialized to that value. Throws an exception if the String cannot be parsed as an int. The radix is assumed to be 10.

Parameters:
s - the String containing the integer
Throws:
NumberFormatException - If the String does not contain a parsable integer.

intValue

public int intValue()
Returns the value of this Integer as an int.

Specified by:
intValue in class Number

longValue

public long longValue()
Returns the value of this Integer as a long.

Specified by:
longValue in class Number

floatValue

public float floatValue()
Returns the value of this Integer as a float.

Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Returns the value of this Integer as a double.

Specified by:
doubleValue in class Number

toString

public String toString()
Returns a String object representing this Integer's value.

Overrides:
toString in class Object

hashCode

public int hashCode()
Returns a hashcode for this Integer.

Overrides:
hashCode in class Object
See Also:
Hashtable

equals

public boolean equals(Object obj)
Compares this object to the specified object.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with
Returns:
true if the objects are the same; false otherwise.
See Also:
Hashtable

getInteger

public static Integer getInteger(String nm)
Gets an Integer property. If the property does not exist, it will return 0.

Parameters:
nm - the property name

getInteger

public static Integer getInteger(String nm,
                                 int val)
Gets an Integer property. If the property does not exist, it will return val. Deals with hexadecimal and octal numbers.

Parameters:
nm - the String name
val - the Integer value

getInteger

public static Integer getInteger(String nm,
                                 Integer val)
Gets an Integer property. If the property does not exist, it will return val. Deals with hexadecimal and octal numbers.

Parameters:
nm - the property name
val - the integer value