Created
November 2, 2014 21:37
-
-
Save vfarcic/1d683808bf3a8d6a7670 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.technologyconversations.java8exercises.streams; | |
import java.util.Comparator; | |
import java.util.List; | |
public class OldestPerson { | |
public static Person getOldestPerson7(List<Person> people) { | |
Person oldestPerson = new Person("", 0); | |
for (Person person : people) { | |
if (person.getAge() > oldestPerson.getAge()) { | |
oldestPerson = person; | |
} | |
} | |
return oldestPerson; | |
} | |
public static Person getOldestPerson(List<Person> people) { | |
return people.stream() // Convert collection to Stream | |
.max(Comparator.comparing(Person::getAge)) // Compares people ages | |
.get(); // Gets stream result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment