Return | Method | Summary |
---|---|---|
static int | compare(double d1, double d2) | Compares the two specified double values. |
int | compareTo(Double anotherDouble) | Compares two Double objects numerically. |
boolean | equals(Object obj) | Compares this object against the specified object. |
static int compare(double d1, double d2) and int compareTo(Double anotherDouble) have the same returns:
Value | Meaning |
---|---|
0 | if anotherDouble is numerically equal to this Double |
less than 0 | if this Double is numerically less than anotherDouble; |
value greater than 0 | if this Double is numerically greater than anotherDouble. |
public class Main {
public static void main(String[] args) {
Double double1 = new Double(1.1);
Double double2 = new Double("1.2");
System.out.println(double1.compareTo(double2));
}
}
The output:
-1
public class Main {
public static void main(String[] args) {
Double double1 = new Double(1.1);
Double double2 = new Double("1.2");
System.out.println(Double.compare(double1,double2));
}
}
The output:
-1
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |