Created
October 30, 2015 10:28
-
-
Save clockworkorange/08d358009ade642bbb9c to your computer and use it in GitHub Desktop.
Java 8 - Lambda: Ordenar lista de objetos
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
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