Double has Double.compare for comparing two double primitives. Why doesn’t Integer have one?
I understand it’s some trivial amount of code to write, but asking out of curiosity.
Edit: I realize both Integer and Double have compareTo. But using compareTo requires boxing the int primitive in an Integer object, which has a pretty high cost. Also, inta > intb is not the same as compare(inta, intb), as the latter returns +1, 0, or -1, while the former is true/false ….
It was a oversight that Java 7 will resolve
http://download.oracle.com/javase/7/docs/api/java/lang/Integer.html#compare%28int,%20int%29
public static int compare(int x,
int y)
Compares two int values numerically. The value returned is identical to what would be returned by:
Parameters:
x – the first int to compare
y – the second int to compare
Returns:
the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y
Since:
1.7