Created
August 6, 2014 17:19
-
-
Save parallelcross/a573edf976f9abcf2ea2 to your computer and use it in GitHub Desktop.
Sort a list in Java with Comparator when you can't extend the class to implement the interface.
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
Collections.sort(tenants, new ScopeComparator()); | |
public class ScopeComparator implements Comparator<Scope> { | |
@Override | |
public int compare(Scope lhs, Scope rhs) { | |
return lhs.getName().compareTo(rhs.getName()); | |
} | |
@Override | |
public boolean equals(Object object) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment