Created
June 2, 2016 10:39
-
-
Save brendandawes/4f23393596ba09c46d2e3e586166db31 to your computer and use it in GitHub Desktop.
Using a Comparator to sort arrays for classes
This file contains hidden or 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.Comparator; | |
import java.util.Collections; | |
Collections.sort(keywords, new CustomComparator()); | |
public class CustomComparator implements Comparator<Keyword> { | |
@Override | |
public int compare(Keyword o1, Keyword o2) { | |
Integer val1 = (Integer) o1.keywordColor; | |
Integer val2 = (Integer) o2.keywordColor; | |
return val1.compareTo(val2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment