|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Number java.lang.Integer
public final class Integer
Instances of class Integer
represent primitive
int
values.
Additionally, this class provides various helper functions and variables
related to ints.
Field Summary | |
---|---|
static int |
MAX_VALUE
The maximum value an int can represent is 2147483647 (or
231 - 1). |
static int |
MIN_VALUE
The minimum value an int can represent is -2147483648 (or
-231). |
static int |
SIZE
The number of bits needed to represent an int . |
static Class |
TYPE
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(String s)
Create an Integer object representing the value of the
argument after conversion to an int . |
Method Summary | |
---|---|
byte |
byteValue()
Return the value of this Integer as a byte . |
int |
compareTo(Integer i)
Compare two Integers numerically by comparing their int
values. |
int |
compareTo(Object o)
Behaves like compareTo(Integer) unless the Object
is not an Integer . |
static Integer |
decode(String str)
Convert the specified String into an Integer . |
double |
doubleValue()
Return the value of this Integer as a double . |
boolean |
equals(Object obj)
Returns true if obj is an instance of
Integer and represents the same int value. |
float |
floatValue()
Return the value of this Integer as a float . |
int |
hashCode()
Return a hashcode representing this Object. |
int |
intValue()
Return the value of this Integer . |
long |
longValue()
Return the value of this Integer as a long . |
static int |
parseInt(String s)
Converts the specified String into an int . |
static int |
parseInt(String str,
int radix)
Converts the specified String into an int
using the specified radix (base). |
short |
shortValue()
Return the value of this Integer as a short . |
static String |
toBinaryString(int i)
Converts the int to a String assuming it is
unsigned in base 2. |
static String |
toHexString(int i)
Converts the int to a String assuming it is
unsigned in base 16. |
static String |
toOctalString(int i)
Converts the int to a String assuming it is
unsigned in base 8. |
String |
toString()
Converts the Integer value to a String and
assumes a radix of 10. |
static String |
toString(int i)
Converts the int to a String and assumes
a radix of 10. |
static String |
toString(int num,
int radix)
Converts the int to a String using
the specified radix (base). |
static Integer |
valueOf(int val)
Returns an Integer object wrapping the value. |
static Integer |
valueOf(String s)
Creates a new Integer object using the String ,
assuming a radix of 10. |
static Integer |
valueOf(String s,
int radix)
Creates a new Integer object using the String
and specified radix (base). |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MIN_VALUE
int
can represent is -2147483648 (or
-231).
public static final int MAX_VALUE
int
can represent is 2147483647 (or
231 - 1).
public static final Class TYPE
int
is represented by this
Class
object.
public static final int SIZE
int
.
Constructor Detail |
---|
public Integer(int value)
Integer
object representing the value of the
int
argument.
value
- the value to usepublic Integer(String s)
Integer
object representing the value of the
argument after conversion to an int
.
s
- the string to convert
NumberFormatException
- if the String does not contain an intvalueOf(String)
Method Detail |
---|
public static String toString(int num, int radix)
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').
num
- the int
to convert to String
radix
- the radix (base) to use in the conversion
String
representation of the argumentpublic static String toHexString(int i)
int
to a String
assuming it is
unsigned in base 16.
i
- the int
to convert to String
String
representation of the argumentpublic static String toOctalString(int i)
int
to a String
assuming it is
unsigned in base 8.
i
- the int
to convert to String
String
representation of the argumentpublic static String toBinaryString(int i)
int
to a String
assuming it is
unsigned in base 2.
i
- the int
to convert to String
String
representation of the argumentpublic static String toString(int i)
int
to a String
and assumes
a radix of 10.
i
- the int
to convert to String
String
representation of the argumenttoString(int, int)
public static int parseInt(String str, int radix)
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 '+'.
str
- the String
to convertradix
- the radix (base) to use in the conversion
String
argument converted to int
NumberFormatException
- if s
cannot be parsed as an
int
public static int parseInt(String s)
String
into an int
.
This function assumes a radix of 10.
s
- the String
to convert
int
value of s
NumberFormatException
- if s
cannot be parsed as an
int
parseInt(String, int)
public static Integer valueOf(String s, int radix)
Integer
object using the String
and specified radix (base).
s
- the String
to convertradix
- the radix (base) to convert with
Integer
NumberFormatException
- if s
cannot be parsed as an
int
parseInt(String, int)
public static Integer valueOf(String s)
Integer
object using the String
,
assuming a radix of 10.
s
- the String
to convert
Integer
NumberFormatException
- if s
cannot be parsed as an
int
Integer(String)
,
parseInt(String)
public static Integer valueOf(int val)
Integer
object wrapping the value.
In contrast to the Integer
constructor, this method
will cache some values. It is used by boxing conversion.
val
- the value to wrap
Integer
public byte byteValue()
Integer
as a byte
.
byteValue
in class Number
public short shortValue()
Integer
as a short
.
shortValue
in class Number
public int intValue()
Integer
.
intValue
in class Number
public long longValue()
Integer
as a long
.
longValue
in class Number
public float floatValue()
Integer
as a float
.
floatValue
in class Number
public double doubleValue()
Integer
as a double
.
doubleValue
in class Number
public String toString()
Integer
value to a String
and
assumes a radix of 10.
toString
in class Object
String
representationObject.getClass()
,
Object.hashCode()
,
Class.getName()
,
toHexString(int)
public int hashCode()
Integer
's hash
code is simply its value.
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean equals(Object obj)
true
if obj
is an instance of
Integer
and represents the same int value.
equals
in class Object
obj
- the object to compare
Object.hashCode()
public static Integer decode(String str)
String
into an Integer
.
The String
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 15
MIN_VALUE
to
MAX_VALUE
, or an exception is thrown.
str
- the String
to interpret
Integer
NumberFormatException
- if s
cannot be parsed as a
int
NullPointerException
- if s
is nullpublic int compareTo(Integer i)
int
values. The result is positive if the first is greater, negative if the
second is greater, and 0 if the two are equal.
i
- the Integer to compare
public int compareTo(Object o)
compareTo(Integer)
unless the Object
is not an Integer
.
compareTo
in interface Comparable
o
- the object to compare
ClassCastException
- if the argument is not an Integer
compareTo(Integer)
,
Comparable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |