Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.lang.Number
java.lang.Integer
Integer
represent primitive
int
values.
Additionally, this class provides various helper functions and variables
related to ints.
Field Summary | |
static int |
|
static int |
|
static int |
|
static Class |
|
Constructor Summary | |
| |
Method Summary | |
static int |
|
byte |
|
static int |
|
int | |
static Integer | |
double |
|
boolean | |
float |
|
static Integer |
|
static Integer |
|
static Integer |
|
int |
|
static int |
|
int |
|
long |
|
static int |
|
static int |
|
static int |
|
static int | |
static int | |
static int |
|
static int |
|
static int |
|
static int |
|
short |
|
static int |
|
static String |
|
static String |
|
static String |
|
String |
|
static String |
|
static String |
|
static Integer |
|
static Integer | |
static Integer |
Methods inherited from class java.lang.Number | |
byteValue , doubleValue , floatValue , intValue , longValue , shortValue |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final int MAX_VALUE
The maximum value anint
can represent is 2147483647 (or 231 - 1).
- Field Value:
- 2147483647
public static final int MIN_VALUE
The minimum value anint
can represent is -2147483648 (or -231).
- Field Value:
- -2147483648
public static final int SIZE
The number of bits needed to represent anint
.
- Field Value:
- 32
- Since:
- 1.5
public static final ClassTYPE
The primitive typeint
is represented by thisClass
object.
- Since:
- 1.1
public Integer(int value)
Create anInteger
object representing the value of theint
argument.
- Parameters:
value
- the value to use
public Integer(String s)
Create anInteger
object representing the value of the argument after conversion to anint
.
- Parameters:
s
- the string to convert
- Throws:
NumberFormatException
- if the String does not contain an int
- See Also:
valueOf(String)
public static int bitCount(int x)
Return the number of bits set in x.
- Parameters:
x
- value to examine
- Since:
- 1.5
public static int compare(int x, int y)
Compares two unboxed int values. The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.
- Parameters:
x
- First value to compare.y
- Second value to compare.
- Returns:
- positive int if the first value is greater, negative if the second is greater, and 0 if the two are equal.
- Since:
- 1.7
public int compareTo(Integer i)
Compare two Integers numerically by comparing theirint
values. The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.
- Parameters:
i
- the Integer to compare
- Returns:
- the comparison
- Since:
- 1.2
public static Integer decode(String str)
Convert the specifiedString
into anInteger
. TheString
may represent decimal, hexadecimal, or octal numbers.The extended BNF grammar is as follows:
DecodableString: ( [Finally, the value must be in the range-
] 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 15MIN_VALUE
toMAX_VALUE
, or an exception is thrown.
- Parameters:
str
- theString
to interpret
- Returns:
- the value of the String as an
Integer
- Throws:
NumberFormatException
- ifs
cannot be parsed as aint
NullPointerException
- ifs
is null
- Since:
- 1.2
public double doubleValue()
Return the value of thisInteger
as adouble
.
- Overrides:
- doubleValue in interface Number
- Returns:
- the double value
public boolean equals(Object obj)
Returnstrue
ifobj
is an instance ofInteger
and represents the same int value.
- Parameters:
obj
- the object to compare
- Returns:
- whether these Objects are semantically equal
public float floatValue()
Return the value of thisInteger
as afloat
.
- Overrides:
- floatValue in interface Number
- Returns:
- the float value
public static Integer getInteger(String nm)
Get the specified system property as anInteger
. Thedecode()
method will be used to interpret the value of the property.
- Parameters:
nm
- the name of the system property
- Returns:
- the system property as an
Integer
, or null if the property is not found or cannot be decoded
- Throws:
SecurityException
- if accessing the system property is forbidden
- See Also:
System.getProperty(String)
,decode(String)
public static Integer getInteger(String nm, int val)
Get the specified system property as anInteger
, or use a defaultint
value if the property is not found or is not decodable. Thedecode()
method will be used to interpret the value of the property.
- Parameters:
nm
- the name of the system propertyval
- the default value
- Returns:
- the value of the system property, or the default
- Throws:
SecurityException
- if accessing the system property is forbidden
- See Also:
System.getProperty(String)
,decode(String)
public static Integer getInteger(String nm, Integer def)
Get the specified system property as anInteger
, or use a defaultInteger
value if the property is not found or is not decodable. Thedecode()
method will be used to interpret the value of the property.
- Parameters:
nm
- the name of the system propertydef
- the default value
- Returns:
- the value of the system property, or the default
- Throws:
SecurityException
- if accessing the system property is forbidden
- See Also:
System.getProperty(String)
,decode(String)
public int hashCode()
Return a hashcode representing this Object.Integer
's hash code is simply its value.
- Returns:
- this Object's hash code
public static int highestOneBit(int value)
Find the highest set bit in value, and return a new value with only that bit set.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static int lowestOneBit(int value)
Find the lowest set bit in value, and return a new value with only that bit set.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static int numberOfLeadingZeros(int value)
Return the number of leading zeros in value.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static int numberOfTrailingZeros(int value)
Find the number of trailing zeros in value.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static int parseInt(String s)
Converts the specifiedString
into anint
. This function assumes a radix of 10.
- Parameters:
s
- theString
to convert
- Returns:
- the
int
value ofs
- Throws:
NumberFormatException
- ifs
cannot be parsed as anint
- See Also:
parseInt(String,int)
public static int parseInt(String str, int radix)
Converts the specifiedString
into anint
using the specified radix (base). The string must not benull
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 byCharacter.digit(d, radix)
, and must be in the range0
toradix - 1
. Finally, the result must be withinMIN_VALUE
toMAX_VALUE
, inclusive. Unlike Double.parseDouble, you may not have a leading '+'.
- Parameters:
str
- theString
to convertradix
- the radix (base) to use in the conversion
- Returns:
- the
String
argument converted toint
- Throws:
NumberFormatException
- ifs
cannot be parsed as anint
public static int rotateLeft(int x, int distance)
Rotate x to the left by distance bits.
- Parameters:
x
- the value to rotatedistance
- the number of bits by which to rotate
- Since:
- 1.5
public static int rotateRight(int x, int distance)
Rotate x to the right by distance bits.
- Parameters:
x
- the value to rotatedistance
- the number of bits by which to rotate
- Since:
- 1.5
public short shortValue()
Return the value of thisInteger
as ashort
.
- Overrides:
- shortValue in interface Number
- Returns:
- the short value
public static int signum(int x)
Return 1 if x is positive, -1 if it is negative, and 0 if it is zero.
- Parameters:
x
- the value to examine
- Since:
- 1.5
public static String toBinaryString(int i)
Converts theint
to aString
assuming it is unsigned in base 2.
- Parameters:
i
- theint
to convert toString
- Returns:
- the
String
representation of the argument
public static String toHexString(int i)
Converts theint
to aString
assuming it is unsigned in base 16.
- Parameters:
i
- theint
to convert toString
- Returns:
- the
String
representation of the argument
public static String toOctalString(int i)
Converts theint
to aString
assuming it is unsigned in base 8.
- Parameters:
i
- theint
to convert toString
- Returns:
- the
String
representation of the argument
public String toString()
Converts theInteger
value to aString
and assumes a radix of 10.
- Returns:
- the
String
representation
public static String toString(int i)
Converts theint
to aString
and assumes a radix of 10.
- Parameters:
i
- theint
to convert toString
- Returns:
- the
String
representation of the argument
- See Also:
toString(int,int)
public static String toString(int num, int radix)
Converts theint
to aString
using the specified radix (base). If the radix exceedsCharacter.MIN_RADIX
orCharacter.MAX_RADIX
, 10 is used instead. If the result is negative, the leading character is '-' ('\\u002D'). The remaining characters come fromCharacter.forDigit(digit, radix)
('0'-'9','a'-'z').
- Parameters:
num
- theint
to convert toString
radix
- the radix (base) to use in the conversion
- Returns:
- the
String
representation of the argument
public static Integer valueOf(int val)
Returns anInteger
object wrapping the value. In contrast to theInteger
constructor, this method will cache some values. It is used by boxing conversion.
- Parameters:
val
- the value to wrap
- Returns:
- the
Integer
public static Integer valueOf(String s)
Creates a newInteger
object using theString
, assuming a radix of 10.
- Parameters:
s
- theString
to convert
- Returns:
- the new
Integer
- Throws:
NumberFormatException
- ifs
cannot be parsed as anint
- See Also:
Integer(String)
,parseInt(String)
public static Integer valueOf(String s, int radix)
Creates a newInteger
object using theString
and specified radix (base).
- Parameters:
s
- theString
to convertradix
- the radix (base) to convert with
- Returns:
- the new
Integer
- Throws:
NumberFormatException
- ifs
cannot be parsed as anint
- See Also:
parseInt(String,int)