stream,filter,map 练习
public class FunctionTest {
private List<Person> people = null;
@Before
public void before() {
Person wu = new Person("小鱼", 18, "男");
Person yu = new Person("kiet", 22, "男");
people = Arrays.asList(wu, yu);
}
@Test
public void Test() {
List<Person> temp = people.stream().filter(person -> "男".equals(person.getSex()) && person.getAge() > 17).collect(toList());
System.out.println(temp);
List<String> names =people.stream().map(person -> person.getName()).collect(toList());
System.out.println(names);
List<Integer> ages = people.stream().map(Person::getAge).collect(toList());
System.out.println(ages);
List<String> sexs = people.stream().map(person -> person.getSex()).collect(toList());
System.out.println(sexs);
}
}