Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Chapter 16: Exploring java.lang 389


The following example creates twoDoubleobjects—one by using adoublevalue and
the other by passing a string that can be parsed as adouble:


class DoubleDemo {
public static void main(String args[]) {
Double d1 = new Double(3.14159);
Double d2 = new Double("314159E-5");


System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
}
}


As you can see from the following output, both constructors created identicalDoubleinstances,
as shown by theequals( )method returningtrue:


3.14159 = 3.14159 –> true

Method Description
boolean isInfinite( ) Returnstrueif the invoking object contains an infinite
value. Other wise, it returnsfalse.
static boolean isInfinite(doublenum) Returnstrueifnumspecifies an infinite value.
Other wise, it returnsfalse.
boolean isNaN( ) Returnstrueif the invoking object contains a value
that is not a number. Other wise, it returnsfalse.
static boolean isNaN(doublenum) Returnstrueifnumspecifies a value that is not a
number. Other wise, it returnsfalse.
static double longBitsToDouble(longnum) Returnsdoubleequivalent of the IEEE-compatible,
double-precision bit pattern specified bynum.
long longValue( ) Returns the value of the invoking object as along.
static double parseDouble(Stringstr)
throws NumberFormatException

Returns thedoubleequivalent of the number contained
in the string specified bystrusing radix 10.
short shortValue( ) Returns the value of the invoking object as ashort.
static String toHexString(doublenum) Returns a string containing the value ofnumin
hexadecimal format.
String toString( ) Returns the string equivalent of the invoking object.
static String toString(doublenum) Returns the string equivalent of the value specified
bynum.
static Double valueOf(doublenum) Returns aDoubleobject containing the value passed
innum.
static Double valueOf(Stringstr)
throws NumberFormatException

Returns aDoubleobject that contains the value
specified by the string instr.

TABLE 16-2 The Methods Defined byDouble(continued)

Free download pdf