Java 6 equivalent of Integer.compare
java
Solution
This is specified in the doc :
Compares two int values numerically. The value returned is identical to what would be returned by: `Integer.valueOf(x).compareTo(Integer.valueOf(y))`
So you can use :
Integer.valueOf(x).compareTo(Integer.valueOf(y))
How do create a similar function in Java 6?
The source is open and you can find the implementation here.
public static int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
Problem
In Java 7 I can use `Integer.compare`, but when I try to use it in Java 6 it gives me the error: ``` cannot find symbol symbol : method compare(int,int) location: class java.lang.Integer ``` How do I create a similar function in Java 6?