Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Created March 21, 2014 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunlebron/9685175 to your computer and use it in GitHub Desktop.
Save shaunlebron/9685175 to your computer and use it in GitHub Desktop.
// source: http://java.dzone.com/articles/using-lambda-expression-sort
// sort by first name
people.sort((p1, p2) -> p1.firstName.compareTo(p2.firstName));
// sort by full name
String fullName(Person p) { return p.firstName + " " + p.lastName; }
people.sort((p1, p2) -> fullName(p1).compareTo(fullName(p2)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment