java.lang
Class Integer
- java.lang.Object
-
- java.lang.Integer
-
public class Integer extends Object
-
-
Field Summary
Fields Modifier and Type Field and Description static int
MAX_VALUE
Constant for the maximumint
value, 231-1static int
MIN_VALUE
Constant for the minimumint
value, -231.
-
Constructor Summary
Constructors Constructor and Description Integer(int value)
Constructs a newInteger
with the specified primitive integer value.
-
Method Summary
Methods Modifier and Type Method and Description byte
byteValue()
Gets the byte value of this int.boolean
equals(Object o)
Compares this instance with the specified object and indicates if they are equal.int
hashCode()
Returns an integer hash code for this int.int
intValue()
Gets the primitive value of this int.long
longValue()
Gets the long value of this int.static int
parseInt(String string)
Parses the specified string as a signed decimal integer value.static int
parseInt(String string, int radix)
Parses the specified string as a signed integer value using the specified radix.short
shortValue()
Gets the short value of this int.static String
toBinaryString(int i)
Converts the specified integer into its binary string representation.static String
toHexString(int i)
Converts the specified integer into its hexadecimal string representation.static String
toOctalString(int i)
Converts the specified integer into its octal string representation.String
toString()
Converts this integer into its decimal string representation.static String
toString(int value)
Converts the specified integer into its decimal string representation.static String
toString(int i, int radix)
Converts the specified integer into a string representation based on the specified radix.static Integer
valueOf(int i)
Returns aInteger
instance for the specified integer value.static Integer
valueOf(String string)
Parses the specified string as a signed decimal integer value.static Integer
valueOf(String string, int radix)
Parses the specified string as a signed integer value using the specified radix.
-
-
-
Field Detail
-
MAX_VALUE
public static final int MAX_VALUE
Constant for the maximumint
value, 231-1- See Also:
- Constant Field Values
-
MIN_VALUE
public static final int MIN_VALUE
Constant for the minimumint
value, -231.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Integer
public Integer(int value)
Constructs a newInteger
with the specified primitive integer value.- Parameters:
value
- the primitive integer value to store in the new instance.
-
-
Method Detail
-
byteValue
public byte byteValue()
Gets the byte value of this int.- Returns:
- this object's byte value.
-
equals
public boolean equals(Object o)
Compares this instance with the specified object and indicates if they are equal. In order to be equal,o
must be an instance ofInteger
and have the same integer value as this object.- Overrides:
equals
in classObject
- Parameters:
o
- the object to compare this integer with.- Returns:
true
if the specified object is equal to thisInteger
;false
otherwise.- See Also:
Object.hashCode()
-
hashCode
public int hashCode()
Returns an integer hash code for this int.- Overrides:
hashCode
in classObject
- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
intValue
public int intValue()
Gets the primitive value of this int.- Returns:
- this object's primitive value.
-
longValue
public long longValue()
Gets the long value of this int.- Returns:
- this object's long value.
-
shortValue
public short shortValue()
Gets the short value of this int.- Returns:
- this object's short value.
-
toString
public String toString()
Converts this 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'.
-
toString
public static String toString(int value)
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'.- Parameters:
value
- the integer to convert.- Returns:
- the decimal string representation of
value
.
-
toString
public static String toString(int i, int radix)
Converts the specified 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. Ifradix
is not in the interval defined byCharacter.MIN_RADIX
andCharacter.MAX_RADIX
then 10 is used as the base for the conversion.- Parameters:
i
- the integer to convert.radix
- the base to use for the conversion.- Returns:
- the string representation of
i
.
-
toBinaryString
public static String toBinaryString(int i)
Converts the specified integer into its binary string representation. The returned string is a concatenation of '0' and '1' characters.- Parameters:
i
- the integer to convert.- Returns:
- the binary string representation of
i
.
-
toHexString
public static String toHexString(int 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'.- Parameters:
i
- the integer to convert.- Returns:
- the hexadecimal string representation of
i
.
-
toOctalString
public static String toOctalString(int i)
Converts the specified integer into its octal string representation. The returned string is a concatenation of characters from '0' to '7'.- Parameters:
i
- the integer to convert.- Returns:
- the octal string representation of
i
.
-
valueOf
public static Integer valueOf(int i)
Returns aInteger
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.- Parameters:
i
- the integer value to store in the instance.- Returns:
- a
Integer
instance containingi
. - Since:
- 1.5
-
valueOf
public static Integer valueOf(String string) throws NumberFormatException
Parses the specified string as a signed decimal integer value.- Parameters:
string
- the string representation of an integer value.- Returns:
- an
Integer
instance containing the integer value represented bystring
. - Throws:
NumberFormatException
- ifstring
isnull
, has a length of zero or can not be parsed as an integer value.- See Also:
parseInt(String)
-
valueOf
public static Integer valueOf(String string, int radix) throws NumberFormatException
Parses the specified string as a signed integer value using the specified radix.- Parameters:
string
- the string representation of an integer value.radix
- the radix to use when parsing.- Returns:
- an
Integer
instance containing the integer value represented bystring
usingradix
. - Throws:
NumberFormatException
- ifstring
isnull
or has a length of zero,radix < Character.MIN_RADIX
,radix > Character.MAX_RADIX
, or ifstring
can not be parsed as an integer value.- See Also:
parseInt(String, int)
-
parseInt
public static int parseInt(String string) throws NumberFormatException
Parses the specified string as a signed decimal integer value. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string
- the string representation of an integer value.- Returns:
- the primitive integer value represented by
string
. - Throws:
NumberFormatException
- ifstring
isnull
, has a length of zero or can not be parsed as an integer value.
-
parseInt
public static int parseInt(String string, int radix) throws NumberFormatException
Parses the specified string as a signed integer value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string
- the string representation of an integer value.radix
- the radix to use when parsing.- Returns:
- the primitive integer value represented by
string
usingradix
. - Throws:
NumberFormatException
- ifstring
isnull
or has a length of zero,radix < Character.MIN_RADIX
,radix > Character.MAX_RADIX
, or ifstring
can not be parsed as an integer value.
-
-