APCS Java Subset

ap.java.lang
Class Double

java.lang.Object
  extended byap.java.lang.Double
All Implemented Interfaces:
Comparable

public class Double
extends java.lang.Object
implements Comparable

The class Double is an immutable wrapper class for the primitive type double, allowing primitive values in some contexts to be treated as objects.

The four methods below are those specified in the APCS Java subset for the wrapper class Double. An object whose type is Double encapsulates a single double value. The methods in the APCS Java subset are applicable to Double objects. Two static methods not in the subset are often useful in practice. These methods, parseDouble and toString are shown in use in the following code.

     String s = Double.toString(3.14159);     // s is "3.14159"
     double d = Double.parseDouble("123.45")  // d is 123.45
 


Constructor Summary
Double(double value)
          Constructs an immutable Double wrapping value.
 
Method Summary
 int compareTo(Object other)
          Compares two Double objects and returns a value consistent with the contract of Comparable.compareTo and with the value returned by Double.equals.
 double doubleValue()
          Returns the value represented by this object.
 boolean equals(Object other)
          Determines if this Double object is equal to another.
 String toString()
          Returns a representation of this object as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Double

public Double(double value)
Constructs an immutable Double wrapping value.

Parameters:
value - is the value wrapped by this object
Method Detail

doubleValue

public double doubleValue()
Returns the value represented by this object.

Returns:
the primitive double value represented by this object

equals

public boolean equals(Object other)
Determines if this Double object is equal to another. In general, this method returns true if and only if this.doubleValue() == other.doubleValue(). However, if both of the values are Double.NaN then this method returns true (see the standard Java API) and if one of the objects is +0.0 and the other is -0.0 then this method returns true.

Parameters:
other - is the other Double object to which this one is compared
Returns:
true if this object is equal to other.

toString

public String toString()
Returns a representation of this object as a string.

Returns:
a string form of this Double object.

compareTo

public int compareTo(Object other)
Compares two Double objects and returns a value consistent with the contract of Comparable.compareTo and with the value returned by Double.equals.

Specified by:
compareTo in interface Comparable
Parameters:
other - is the Double object to which this one is compared
Returns:
the value 0 if this object is equal to other, a value less than 0 if this object is less than other, and a value greater than 0 if this object is greater than other

unofficial documentation for the APCS Java Subset