java.lang
Class Integer
java.lang.Object
|
+--java.lang.Number
|
+--java.lang.Integer
All Implemented Interfaces:
Comparable, Serializable
Instances of class Integer
represent primitive
int
values.
Additionally, this class provides various helper functions and variables
related to ints.
Since:Authors:- Paul Fisher
- John Keiser
- Warren Levy
- Eric Blake <ebb9@email.byu.edu>
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:
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:
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:
- the value of the String as an
Integer
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:
- whether these Objects are semantically equal
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:
- the system property as an
Integer
, or null if the
property is not found or cannot be decoded
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:
- the value of the system property, or the default
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:
- the value of the system property, or the default
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:
- the
String
argument converted to int
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:
- the
String
representation of the argument
toHexString
public static String toHexString(int i)
Converts the int
to a String
assuming it is
unsigned in base 16.
Parameters:
Returns:
- the
String
representation of the argument
toOctalString
public static String toOctalString(int i)
Converts the int
to a String
assuming it is
unsigned in base 8.
Parameters:
Returns:
- the
String
representation of the argument
toString
public String toString()
Converts the Integer
value to a String
and
assumes a radix of 10.
Returns:
- the
String
representation
toString
public static String toString(int i)
Converts the int
to a String
and assumes
a radix of 10.
Parameters:
Returns:
- the
String
representation of the argument
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:
- the
String
representation of the argument
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:
Integer
represent primitiveint
values. Additionally, this class provides various helper functions and variables related to ints.