Skip to content

Instantly share code, notes, and snippets.

@clockworkorange
Created October 30, 2015 10:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clockworkorange/08d358009ade642bbb9c to your computer and use it in GitHub Desktop.
Save clockworkorange/08d358009ade642bbb9c to your computer and use it in GitHub Desktop.
Java 8 - Lambda: Ordenar lista de objetos
class Book {
String title;
String author;
Date date;
}
Book book1 = new Book("Refactoring", "Martin Fowler", new Date());
Book book2 = new Book("Clean code", "Robert C. Martin", new Date());
Book book3 = new Book("Test Driven Development", "Kent Beck", new Date());
List<Book> books = Arrays.asList(book2, book1, book3);
books.stream()
.sorted((bookObject1, bookObject2) ->
bookObject1.getHeader().getDate().compareTo(bookObject2.getHeader().getDate()))
.collect(Collectors.toList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment