Skip to content

Instantly share code, notes, and snippets.

@parallelcross
Created August 6, 2014 17:19
Show Gist options
  • Save parallelcross/a573edf976f9abcf2ea2 to your computer and use it in GitHub Desktop.
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.
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