Team LiB
Previous Section Next Section


Java 1.0serializable comparable

This class provides an immutable object wrapper around the double primitive data type. doubleValue( ) returns the primitive double value of a Double object, and there are other methods (which override Number methods and whose names all end in "Value") for returning a the wrapped double value as a variety of other primitive types.

This class also provides some useful constants and static methods for testing double values. MIN_VALUE and MAX_VALUE are the smallest (closest to zero) and largest representable double values. POSITIVE_INFINITY and NEGATIVE_INFINITY are the double representations of infinity and negative infinity, and NaN is special double "not a number" value. isInfinite( ) in class and instance method forms tests whether a double or a Double has an infinite value. Similarly, isNaN( ) tests whether a double or Double is not-a-number; this is a comparison that cannot be done directly because the NaN constant never tests equal to any other value, including itself.

The static parseDouble( ) method converts a String to a double. The static valueOf( ) converts a String to a Double, and is basically equivalent to the Double( ) constructor that takes a String argument. The static and instance toString( ) methods perform the opposite conversion: they convert a double or a Double to a String. See also java.text.NumberFormat for more flexible number parsing and formatting.

The compareTo( ) method makes Double object Comparable which is useful for ordering and sorting. The static compare( ) method is similar (its return values have the same meaning as those of Comparable.compareTo( )) but works on primitive values rather than objects and is useful when ordering and sorting arrays of double values.

doubleToLongBits( ), doubleToRawBits( ) and longBitsToDouble( ) allow you to manipulate the bit representation (defined by IEEE 754) of a double directly (which is not something that most applications ever need to do).

Figure 10-17. java.lang.Double

public final class Double extends Number implements Comparable<Double> {
// Public Constructors
     public Double(String s) throws NumberFormatException;  
     public Double(double value);  
// Public Constants
     public static final double MAX_VALUE; =1.7976931348623157E308
     public static final double MIN_VALUE; =4.9E-324
     public static final double NaN;       =NaN
     public static final double NEGATIVE_INFINITY;                       =-Infinity
     public static final double POSITIVE_INFINITY;                       =Infinity
5.0  public static final int SIZE;     =64
1.1  public static final Class<Double> TYPE;  
// Public Class Methods
1.4  public static int compare(double d1, double d2);  
     public static long doubleToLongBits(double value);                 native
1.3  public static long doubleToRawLongBits(double value);          native
     public static boolean isInfinite(double v);  
     public static boolean isNaN(double v);  
     public static double longBitsToDouble(long bits);                  native
1.2  public static double parseDouble(String s) throws NumberFormatException;  
5.0  public static String toHexString(double d);  
     public static String toString(double d);  
     public static Double valueOf(String s) throws NumberFormatException;  
5.0  public static Double valueOf(double d);  
// Public Instance Methods
     public boolean isInfinite( );  
     public boolean isNaN( );  
// Methods Implementing Comparable
1.2  public int compareTo(Double anotherDouble);  
// Public Methods Overriding Number
1.1  public byte byteValue( );  
     public double doubleValue( );  
     public float floatValue( );  
     public int intValue( );  
     public long longValue( );  
1.1  public short shortValue( );  
// Public Methods Overriding Object
     public boolean equals(Object obj);  
     public int hashCode( );  
     public String toString( );  

    Team LiB
    Previous Section Next Section