Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.lang

Class Integer

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

All Implemented Interfaces:

Comparable, Serializable


public final class Integer

extends Number

implements Comparable

Instances of class Integer represent primitive int values. Additionally, this class provides various helper functions and variables related to ints.

Since:Authors:

Field Summary

static intMAX_VALUE

The maximum value an int can represent is 2147483647 (or 231 - 1).
static intMIN_VALUE

The minimum value an int can represent is -2147483648 (or -231).
static java.lang.ClassTYPE

The primitive type int is represented by this Class object.

Constructor Summary

Integer(int value)

Create an Integer object representing the value of the int argument.
Integer(java.lang.String s)

Create an Integer object representing the value of the argument after conversion to an int.

Method Summary

bytebyteValue()

Return the value of this Integer as a byte.
intcompareTo(java.lang.Integer i)

Compare two Integers numerically by comparing their int values.
intcompareTo(java.lang.Object o)

Behaves like compareTo(Integer) unless the Object is not an Integer.
static java.lang.Integerdecode(java.lang.String str)

Convert the specified String into an Integer.
doubledoubleValue()

Return the value of this Integer as a double.
booleanequals(java.lang.Object obj)

Returns true if obj is an instance of Integer and represents the same int value.
floatfloatValue()

Return the value of this Integer as a float.
static java.lang.IntegergetInteger(java.lang.String nm)

Get the specified system property as an Integer.
static java.lang.IntegergetInteger(java.lang.String nm, int val)

Get the specified system property as an Integer, or use a default int value if the property is not found or is not decodable.
static java.lang.IntegergetInteger(java.lang.String nm, java.lang.Integer def)

Get the specified system property as an Integer, or use a default Integer value if the property is not found or is not decodable.
inthashCode()

Return a hashcode representing this Object.
intintValue()

Return the value of this Integer.
longlongValue()

Return the value of this Integer as a long.
static intparseInt(java.lang.String str, int radix)

Converts the specified String into an int using the specified radix (base).
static intparseInt(java.lang.String s)

Converts the specified String into an int.
shortshortValue()

Return the value of this Integer as a short.
static java.lang.StringtoBinaryString(int i)

Converts the int to a String assuming it is unsigned in base 2.
static java.lang.StringtoHexString(int i)

Converts the int to a String assuming it is unsigned in base 16.
static java.lang.StringtoOctalString(int i)

Converts the int to a String assuming it is unsigned in base 8.
static java.lang.StringtoString(int num, int radix)

Converts the int to a String using the specified radix (base).
static java.lang.StringtoString(int i)

Converts the int to a String and assumes a radix of 10.
java.lang.StringtoString()

Converts the Integer value to a String and assumes a radix of 10.
static java.lang.IntegervalueOf(java.lang.String s, int radix)

Creates a new Integer object using the String and specified radix (base).
static java.lang.IntegervalueOf(java.lang.String s)

Creates a new Integer object using the String, assuming a radix of 10.

Field Details

MAX_VALUE

public static final int MAX_VALUE

The maximum value an int can represent is 2147483647 (or 231 - 1).


MIN_VALUE

public static final int MIN_VALUE

The minimum value an int can represent is -2147483648 (or -231).


TYPE

public static final Class TYPE

The primitive type int is represented by this Class object.

Since:

Constructor Details

Integer

public Integer(int value)

Create an Integer object representing the value of the int argument.

Parameters:


Integer

public Integer(java.lang.String s)

Create an Integer object representing the value of the argument after conversion to an int.

Parameters:

Throws:

See Also:


Method Details

byteValue

public byte byteValue()

Return the value of this Integer as a byte.

Returns:


compareTo

public int compareTo(java.lang.Integer i)

Compare two Integers numerically by comparing their int values. The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.

Since:Parameters:

Returns:


compareTo

public int compareTo(java.lang.Object o)

Behaves like compareTo(Integer) unless the Object is not an Integer.

Since:Parameters:

Returns:

Throws:

See Also:


decode

public static Integer decode(java.lang.String str)

Convert the specified String into an Integer. The String may represent decimal, hexadecimal, or octal numbers.

The extended BNF grammar is as follows:

 DecodableString:
      ( [ - ] DecimalNumber )
    | ( [ - ] ( 0x | 0X
              | # ) HexDigit { HexDigit } )
    | ( [ - ] 0 { OctalDigit } )
 DecimalNumber:
        DecimalDigit except '0' { DecimalDigit }
 DecimalDigit:
        Character.digit(d, 10) has value 0 to 9
 OctalDigit:
        Character.digit(d, 8) has value 0 to 7
 DecimalDigit:
        Character.digit(d, 16) has value 0 to 15
 
Finally, the value must be in the range MIN_VALUE to MAX_VALUE, or an exception is thrown.

Since:Parameters:

Returns:

Throws:


doubleValue

public double doubleValue()

Return the value of this Integer as a double.

Returns:


equals

public boolean equals(java.lang.Object obj)

Returns true if obj is an instance of Integer and represents the same int value.

Parameters:

Returns:


floatValue

public float floatValue()

Return the value of this Integer as a float.

Returns:


getInteger

public static Integer getInteger(java.lang.String nm)

Get the specified system property as an Integer. The decode() method will be used to interpret the value of the property.

Parameters:

Returns:

Throws:

See Also:


getInteger

public static Integer getInteger(java.lang.String nm, int val)

Get the specified system property as an Integer, or use a default int value if the property is not found or is not decodable. The decode() method will be used to interpret the value of the property.

Parameters:

Returns:

Throws:

See Also:


getInteger

public static Integer getInteger(java.lang.String nm, java.lang.Integer def)

Get the specified system property as an Integer, or use a default Integer value if the property is not found or is not decodable. The decode() method will be used to interpret the value of the property.

Parameters:

Returns:

Throws:

See Also:


hashCode

public int hashCode()

Return a hashcode representing this Object. Integer's hash code is simply its value.

Returns:


intValue

public int intValue()

Return the value of this Integer.

Returns:


longValue

public long longValue()

Return the value of this Integer as a long.

Returns:


parseInt

public static int parseInt(java.lang.String s)

Converts the specified String into an int. This function assumes a radix of 10.

Parameters:

Returns:

Throws:

See Also:


parseInt

public static int parseInt(java.lang.String str, int radix)

Converts the specified String into an int using the specified radix (base). The string must not be null or empty. It may begin with an optional '-', which will negate the answer, provided that there are also valid digits. Each digit is parsed as if by Character.digit(d, radix), and must be in the range 0 to radix - 1. Finally, the result must be within MIN_VALUE to MAX_VALUE, inclusive. Unlike Double.parseDouble, you may not have a leading '+'.

Parameters:

Returns:

Throws:


shortValue

public short shortValue()

Return the value of this Integer as a short.

Returns:


toBinaryString

public static String toBinaryString(int i)

Converts the int to a String assuming it is unsigned in base 2.

Parameters:

Returns:


toHexString

public static String toHexString(int i)

Converts the int to a String assuming it is unsigned in base 16.

Parameters:

Returns:


toOctalString

public static String toOctalString(int i)

Converts the int to a String assuming it is unsigned in base 8.

Parameters:

Returns:


toString

public String toString()

Converts the Integer value to a String and assumes a radix of 10.

Returns:


toString

public static String toString(int i)

Converts the int to a String and assumes a radix of 10.

Parameters:

Returns:

See Also:


toString

public static String toString(int num, int radix)

Converts the int to a String using the specified radix (base). If the radix exceeds Character.MIN_RADIX or Character.MAX_RADIX, 10 is used instead. If the result is negative, the leading character is '-' ('\\u002D'). The remaining characters come from Character.forDigit(digit, radix) ('0'-'9','a'-'z').

Parameters:

Returns:


valueOf

public static Integer valueOf(java.lang.String s)

Creates a new Integer object using the String, assuming a radix of 10.

Parameters:

Returns:

Throws:

See Also:


valueOf

public static Integer valueOf(java.lang.String s, int radix)

Creates a new Integer object using the String and specified radix (base).

Parameters:

Returns:

Throws:

See Also: