Created
August 19, 2014 23:55
-
-
Save ploxiln/c6bfbbb9cf1c214cf896 to your computer and use it in GitHub Desktop.
in response to https://gist.github.com/mccutchen/831a1da33e1f8c74f994
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
auto-boxing and auto-unboxing