Java Reference
In-Depth Information
java.lang.Integer
java.lang.Double
-value: int
+MAX_VALUE: int
+ MIN_VALUE: int
-value: double
+MAX_VALUE: double
+MIN_VALUE: double
+Integer(value: int)
+Integer(s: String)
+byteValue(): byte
+shortValue(): short
+intValue(): int
+longValue(): long
+floatValue(): float
+doubleValue(): double
+compareTo(o: Integer): int
+toString(): String
+valueOf(s: String): Integer
+ valueOf(s: String, radix: int): Integer
+parseInt(s: String): int
+parseInt(s: String, radix: int): int
+Double(value: double)
+Double(s: String)
+byteValue(): byte
+shortValue(): short
+intValue(): int
+longValue(): long
+floatValue(): float
+doubleValue(): double
+compareTo(o: Double): int
+toString(): String
+valueOf(s: String): Double
+valueOf(s: String, radix: int): Double
+parseDouble(s: String): double
+parseDouble(s: String, radix: int): double
F IGURE 10.14
The wrapper classes provide constructors, constants, and conversion methods for manipulating various
data types.
You can construct a wrapper object either from a primitive data type value or from a string
representing the numeric value—for example, new Double(5.0) , new Double("5.0") ,
new Integer(5) , and new Integer("5") .
The wrapper classes do not have no-arg constructors. The instances of all wrapper classes
are immutable; this means that, once the objects are created, their internal values cannot be
changed.
Each numeric wrapper class has the constants MAX_VALUE and MIN_VALUE . MAX_VALUE
represents the maximum value of the corresponding primitive data type. For Byte , Short ,
Integer , and Long , MIN_VALUE represents the minimum byte , short , int , and long
values. For Float and Double , MIN_VALUE represents the minimum positive float and
double values. The following statements display the maximum integer (2,147,483,647),
the minimum positive float (1.4E-45), and the maximum double floating-point number
(1.79769313486231570e
constructors
no no-arg constructor
immutable
constants
+
308d).
System.out.println( "The maximum integer is " + Integer.MAX_VALUE);
System.out.println( "The minimum positive float is " +
Float.MIN_VALUE);
System.out.println(
"The maximum double-precision floating-point number is " +
Double.MAX_VALUE);
Each numeric wrapper class contains the methods doubleValue() , floatValue() ,
intValue() , longValue() , and shortValue() for returning a double , float , int ,
long , or short value for the wrapper object. For example,
conversion methods
new Double(12.4).intValue() returns 12 ;
new Integer(12).doubleValue() returns 12.0 ;
Recall that the String class contains the compareTo method for comparing two strings.
The numeric wrapper classes contain the compareTo method for comparing two numbers
compareTo method
 
 
Search WWH ::




Custom Search