|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Number
java.lang.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 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. |
static Integer |
getInteger(String nm)
Get the specified system property as an Integer. |
static Integer |
getInteger(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. |
static Integer |
getInteger(String nm,
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. |
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(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 |
| 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.
| 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 Stringradix - 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 '+'.
radix - the radix (base) to use in the conversion
String argument converted to int
NumberFormatException - if s cannot be parsed as an
intpublic 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
intparseInt(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
intparseInt(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
intInteger(String),
parseInt(String)public byte byteValue()
Integer as a byte.
byteValue in class Numberpublic short shortValue()
Integer as a short.
shortValue in class Numberpublic int intValue()
Integer.
intValue in class Numberpublic long longValue()
Integer as a long.
longValue in class Numberpublic float floatValue()
Integer as a float.
floatValue in class Numberpublic double doubleValue()
Integer as a double.
doubleValue in class Numberpublic String toString()
Integer value to a String and
assumes a radix of 10.
toString in class ObjectString representationpublic int hashCode()
Integer's hash
code is simply its value.
hashCode in class Objectpublic boolean equals(Object obj)
true if obj is an instance of
Integer and represents the same int value.
equals in class Objectobj - the object to compare
public static Integer getInteger(String nm)
Integer. The
decode() method will be used to interpret the value of
the property.
nm - the name of the system property
Integer, or null if the
property is not found or cannot be decoded
SecurityException - if accessing the system property is forbiddenSystem.getProperty(String),
decode(String)
public static Integer getInteger(String nm,
int val)
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.
nm - the name of the system propertyval - the default value
SecurityException - if accessing the system property is forbiddenSystem.getProperty(String),
decode(String)
public static Integer getInteger(String nm,
Integer def)
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.
nm - the name of the system property
SecurityException - if accessing the system property is forbiddenSystem.getProperty(String),
decode(String)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:
( [ - ] 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.
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.
o - the object to compare
ClassCastException - if the argument is not an IntegercompareTo(Integer),
Comparable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||