Java Reference
In-Depth Information
Integer ( int value)
Constructor: creates a new Integer object storing the specified value.
byte byteValue ()
double doubleValue ()
float floatValue ()
int intValue ()
long longValue ()
Return the value of this Integer as the corresponding primitive type.
static int parseInt (String str)
Returns the int corresponding to the value stored in the
specified string.
static String toBinaryString ( int num)
static String tohexString ( int num)
static String toOctalString ( int num)
Returns a string representation of the specified integer value in the
corresponding base.
FIGURE 3.9 Some methods of the Integer class
Wrapper classes also provide various methods related to the management of
the associated primitive type. For example, the Integer class contains methods
that return the int value stored in the object and that convert the stored value to
other primitive types. Figure 3.9 lists some of the methods found in the Integer
class. The other wrapper classes have similar methods.
Note that the wrapper classes also contain static methods that can be invoked
independent of any instantiated object. For example, the Integer class contains a
static method called parseInt to convert an integer that is stored in a String to
its corresponding int value. If the String object str holds the string "987" , the
following line of code converts the string into the integer value 987 and stores that
value in the int variable num :
num = Integer.parseInt(str);
The Java wrapper classes often contain static constants that are helpful as
well. For example, the Integer class contains two constants, MIN_VALUE and
MAX_VALUE , that hold the smallest and largest int values, respectively. The other
wrapper classes contain similar constants for their types.
 
Search WWH ::




Custom Search