Instantly share code, notes, and snippets.

@cajar1988 /filterCity.java Secret
Last active Oct 30, 2015

Embed
What would you like to do?
public List<Person> fetchPeopleFrom_pureJava(String city) {
List<Person> result = new ArrayList<>();
List<Person> allPersons = fetchAll();
for (Person person : allPersons) {
Address address = person.getAddress();
String personCity = address.getCity();
if (personCity.equals(city)) {
result.add(person);
}
}
return result;
}
public List<Person> fetchPeopleFrom_jdk8(String city) {
return fetchAll().stream()
.filter(person -> person.getAddress().getCity().equals(city))
.collect(toList());
}
public javaslang.collection.List<Person> fetchPeopleFrom_jslang(String city) {
return ofAll(fetchAll())
.filter(person -> person.getAddress().getCity().equals(city));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment