Java Reference
In-Depth Information
intValue() . Class Integer has a few other useful instance methods.
For example, there is a second constructor, which can be used to translate a
String value into a wrapped Integer . The String argument of the constructor
call is converted into an int , and a new instance of class Integer is created that
wraps it. The result of the new-expression is the name of the new instance. Here
is an example of its use:
Integer d= new Integer("254");
This constructor is useful when a string is read in using, for example, GUI
JLiveWindow :
Integer e= new Integer(JLiveWindow.getStringField(0));
Class Integer has methods for converting a wrapped value to a different
primitive type and to a String . For example, with e containing an Integer , we
can obtain its wrapped value using these function calls:
There is a method for comparing the wrapped value with another value:
/** = "x is an instance of Integer and its wrapped value
equals this wrapped value " */
public boolean equals(Integer x)
The argument of equals can be any class instance, but if it is not an instance of
class Integer , the result is false , e.g.
d.equals( new Long(254))
is false no matter what value d wraps.
Static components of class Integer
Class Integer is a good place to house static components that deal with
primitive type int . Two constants, i.e. variables with qualifier final , are:
Integer.MAX_VALUE; // Largest value of type int
Integer.MIN_VALUE; // Smallest value of type int
The specification does not say what these values actually are, but you can write
code to print them and use them in expressions, e.g.
Lesson page 5-
1 contains info
on static com-
ponents of
class Integer.
d= Integer.MIN_VALUE + 1;
Class Integer contains a method for translating an int value x to a String ;
here is a call to it:
Search WWH ::

Custom Search