Skip to content

Instantly share code, notes, and snippets.

@ploxiln
Created August 19, 2014 23:55
Show Gist options
  • Save ploxiln/c6bfbbb9cf1c214cf896 to your computer and use it in GitHub Desktop.
Save ploxiln/c6bfbbb9cf1c214cf896 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Comparator;
class EvenFirst implements Comparator<Integer> {
public int compare(Integer a, Integer b) {
return a % 2 - b % 2;
}
}
public class SortTest {
static void sortTest() {
Integer[] xs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// Sort those Integer objects
Arrays.sort(xs, new EvenFirst());
Integer[] expected = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9};
System.out.println("Got expected results? " + Arrays.equals(xs, expected));
}
public static void main(String[] args) {
sortTest();
}
}
@ploxiln
Copy link
Author

ploxiln commented Aug 20, 2014

auto-boxing and auto-unboxing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment