import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; class Person { private Integer age; private String name; public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Person(Integer age, String name) { super(); this.age = age; this.name = name; } @Override public String toString() { return "Person [age=" + age + ", name=" + name + "]"; } } public class JavaStreamFilter { public static void main(String[] args) { List<Person> people = getArrayList(); List<Person> oldPeople = people.stream().filter(p -> p.getAge() > 30).collect(Collectors.toList()); System.out.println("\nThe sorted list:"); displayList(oldPeople); } private static void displayList(List<Person> people) { for (Person p : people) { System.out.println(p); } } private static List<Person> getArrayList() { List<Person> people = new ArrayList<Person>(); Person person1 = new Person(21, "Jack Lee"); people.add(person1); Person person2 = new Person(31, "Jack Ma"); people.add(person2); Person person3 = new Person(12, "Steve Liu"); people.add(person3); Person person4 = new Person(42, "Alice XU"); people.add(person4); return people; } The result is: The sorted list: Person [age=31, name=Jack Ma] Person [age=42, name=Alice XU]