stream 以一种声明的方式处理数据
基本方法
filter:通过设置的条件过滤出数据
public class StreamTest {
private List<User> userList;
public void init(){
List<User> userList = new ArrayList<>();
User user = new User("张三", SexEnum.MAN,10);
User user1 = new User("李四", SexEnum.MAN,14);
User user2 = new User("王五", SexEnum.WOMAN,12);
userList.add(user);
userList.add(user1);
userList.add(user2);
this.userList = userList;
}
@Test
public void fun1(){
init();
//统计女生数量(filter做条件过滤)
long i = userList.stream().filter