java.lang.Object | ||
↳ | java.lang.Number | |
↳ | java.lang.Integer |
The wrapper for the primitive type int
.
Implementation note: The "bit twiddling" methods in this class use techniques described in Henry S. Warren, Jr.'s Hacker's Delight, (Addison Wesley, 2002) and Sean Anderson's Bit Twiddling Hacks.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | MAX_VALUE | Constant for the maximum int value, 231-1. |
|||||||||
int | MIN_VALUE | Constant for the minimum int value, -231. |
|||||||||
int | SIZE | Constant for the number of bits needed to represent an int in
two's complement form. |
|||||||||
Class<Integer> | TYPE | The Class object that represents the primitive type int . |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
Integer with the specified primitive integer
value. | |||||||||||
Constructs a new
Integer from the specified string. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Counts the number of 1 bits in the specified integer; this is also
referred to as population count.
| |||||||||||
Returns this object's value as a byte.
| |||||||||||
Compares this object to the specified integer object to determine their
relative order.
| |||||||||||
Parses the specified string and returns a
Integer instance if the
string can be decoded into an integer value. | |||||||||||
Returns this object's value as a double.
| |||||||||||
Compares this instance with the specified object and indicates if they
are equal.
| |||||||||||
Returns this object's value as a float.
| |||||||||||
Returns the
Integer value of the system property identified by
string . | |||||||||||
Returns the
Integer value of the system property identified by
string . | |||||||||||
Returns the
Integer value of the system property identified by
string . | |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Determines the highest (leftmost) bit of the specified integer that is 1
and returns the bit mask value for that bit.
| |||||||||||
Gets the primitive value of this int.
| |||||||||||
Returns this object's value as a long.
| |||||||||||
Determines the lowest (rightmost) bit of the specified integer that is 1
and returns the bit mask value for that bit.
| |||||||||||
Determines the number of leading zeros in the specified integer prior to
the
highest one bit . | |||||||||||
Determines the number of trailing zeros in the specified integer after
the
lowest one bit . | |||||||||||
Parses the specified string as a signed decimal integer value.
| |||||||||||
Parses the specified string as a signed integer value using the specified
radix.
| |||||||||||
Reverses the order of the bits of the specified integer.
| |||||||||||
Reverses the order of the bytes of the specified integer.
| |||||||||||
Rotates the bits of the specified integer to the left by the specified
number of bits.
| |||||||||||
Rotates the bits of the specified integer to the right by the specified
number of bits.
| |||||||||||
Returns this object's value as a short.
| |||||||||||
Returns the value of the
signum function for the specified
integer. | |||||||||||
Converts the specified integer into its binary string representation.
| |||||||||||
Converts the specified integer into its hexadecimal string
representation.
| |||||||||||
Converts the specified integer into its octal string representation.
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
| |||||||||||
Converts the specified integer into its decimal string representation.
| |||||||||||
Converts the specified signed integer into a string representation based on the
specified radix.
| |||||||||||
Parses the specified string as a signed integer value using the specified
radix.
| |||||||||||
Returns a
Integer instance for the specified integer value. | |||||||||||
Parses the specified string as a signed decimal integer value.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Number
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.lang.Comparable
|
Constant for the maximum int
value, 231-1.
Constant for the minimum int
value, -231.
Constant for the number of bits needed to represent an int
in
two's complement form.
The Class
object that represents the primitive type int
.
Constructs a new Integer
with the specified primitive integer
value.
value | the primitive integer value to store in the new instance. |
---|
Constructs a new Integer
from the specified string.
string | the string representation of an integer value. |
---|
NumberFormatException | if string can not be decoded into an integer value. |
---|
Counts the number of 1 bits in the specified integer; this is also referred to as population count.
i | the integer to examine. |
---|
i
.Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.
Compares this object to the specified integer object to determine their relative order.
object | the integer object to compare this object to. |
---|
object
; 0 if the value of this integer and the
value of object
are equal; a positive value if the value
of this integer is greater than the value of object
.Parses the specified string and returns a Integer
instance if the
string can be decoded into an integer value. The string may be an
optional minus sign "-" followed by a hexadecimal ("0x..." or "#..."),
octal ("0..."), or decimal ("...") representation of an integer.
string | a string representation of an integer value. |
---|
Integer
containing the value represented by
string
.NumberFormatException | if string can not be parsed as an integer value.
|
---|
Returns this object's value as a double. Might involve rounding.
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, o
must be an instance of
Integer
and have the same integer value as this object.
o | the object to compare this integer with. |
---|
true
if the specified object is equal to this
Integer
; false
otherwise.
Returns this object's value as a float. Might involve rounding.
Returns the Integer
value of the system property identified by
string
. Returns the specified default value if string
is
null
or empty, if the property can not be found or if its value
can not be parsed as an integer.
string | the name of the requested system property. |
---|---|
defaultValue | the default value that is returned if there is no integer system property with the requested name. |
Integer
or the
default value.
Returns the Integer
value of the system property identified by
string
. Returns null
if string
is null
or empty, if the property can not be found or if its value can not be
parsed as an integer.
string | the name of the requested system property. |
---|
Integer
or
null
.
Returns the Integer
value of the system property identified by
string
. Returns the specified default value if string
is
null
or empty, if the property can not be found or if its value
can not be parsed as an integer.
string | the name of the requested system property. |
---|---|
defaultValue | the default value that is returned if there is no integer system property with the requested name. |
Integer
or the
default value.
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct hashCode
method
if you intend implementing your own hashCode
method.
Determines the highest (leftmost) bit of the specified integer that is 1 and returns the bit mask value for that bit. This is also referred to as the Most Significant 1 Bit. Returns zero if the specified integer is zero.
i | the integer to examine. |
---|
i
.Gets the primitive value of this int.
Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.
Determines the lowest (rightmost) bit of the specified integer that is 1 and returns the bit mask value for that bit. This is also referred to as the Least Significant 1 Bit. Returns zero if the specified integer is zero.
i | the integer to examine. |
---|
i
.Determines the number of leading zeros in the specified integer prior to
the highest one bit
.
i | the integer to examine. |
---|
i
.Determines the number of trailing zeros in the specified integer after
the lowest one bit
.
i | the integer to examine. |
---|
i
.Parses the specified string as a signed decimal integer value. The ASCII character - ('-') is recognized as the minus sign.
string | the string representation of an integer value. |
---|
string
.NumberFormatException | if string is null , has a length of zero or
can not be parsed as an integer value.
|
---|
Parses the specified string as a signed integer value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.
string | the string representation of an integer value. |
---|---|
radix | the radix to use when parsing. |
string
using
radix
.NumberFormatException | if string is null or has a length of zero,
radix < Character.MIN_RADIX ,
radix > Character.MAX_RADIX , or if string
can not be parsed as an integer value.
|
---|
Reverses the order of the bits of the specified integer.
i | the integer value for which to reverse the bit order. |
---|
Reverses the order of the bytes of the specified integer.
i | the integer value for which to reverse the byte order. |
---|
Rotates the bits of the specified integer to the left by the specified number of bits.
i | the integer value to rotate left. |
---|---|
distance | the number of bits to rotate. |
Rotates the bits of the specified integer to the right by the specified number of bits.
i | the integer value to rotate right. |
---|---|
distance | the number of bits to rotate. |
Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.
Returns the value of the signum
function for the specified
integer.
i | the integer value to check. |
---|
i
is negative, 1 if i
is positive, 0 if
i
is zero.Converts the specified integer into its binary string representation. The returned string is a concatenation of '0' and '1' characters.
i | the integer to convert. |
---|
i
.
Converts the specified integer into its hexadecimal string representation. The returned string is a concatenation of characters from '0' to '9' and 'a' to 'f'.
i | the integer to convert. |
---|
i
.
Converts the specified integer into its octal string representation. The returned string is a concatenation of characters from '0' to '7'.
i | the integer to convert. |
---|
i
.
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful toString
method
if you intend implementing your own toString
method.
Converts the specified integer into its decimal string representation. The returned string is a concatenation of a minus sign if the number is negative and characters from '0' to '9'.
i | the integer to convert. |
---|
i
.
Converts the specified signed integer into a string representation based on the
specified radix. The returned string is a concatenation of a minus sign
if the number is negative and characters from '0' to '9' and 'a' to 'z',
depending on the radix. If radix
is not in the interval defined
by Character.MIN_RADIX
and Character.MAX_RADIX
then 10 is
used as the base for the conversion.
This method treats its argument as signed. If you want to convert an
unsigned value to one of the common non-decimal bases, you may find
toBinaryString(int)
, #toHexString
, or toOctalString(int)
more convenient.
i | the signed integer to convert. |
---|---|
radix | the base to use for the conversion. |
i
.
Parses the specified string as a signed integer value using the specified radix.
string | the string representation of an integer value. |
---|---|
radix | the radix to use when parsing. |
Integer
instance containing the integer value
represented by string
using radix
.NumberFormatException | if string is null or has a length of zero,
radix < Character.MIN_RADIX ,
radix > Character.MAX_RADIX , or if string
can not be parsed as an integer value. |
---|
Returns a Integer
instance for the specified integer value.
If it is not necessary to get a new Integer
instance, it is
recommended to use this method instead of the constructor, since it
maintains a cache of instances which may result in better performance.
i | the integer value to store in the instance. |
---|
Integer
instance containing i
.Parses the specified string as a signed decimal integer value.
string | the string representation of an integer value. |
---|
Integer
instance containing the integer value
represented by string
.NumberFormatException | if string is null , has a length of zero or
can not be parsed as an integer value. |
---|