3 List过滤(filter)

作者: 笑Skr人啊 | 来源:发表于2019-11-13 16:09 被阅读0次
package com.gp6.list.filter;

import com.gp6.bean.Employee;
import com.gp6.list.utils.ListUtil;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 测试list过滤
 *
 * @author gp6
 * @date 2019-07-23
 */
public class TestFilter {

    public static void main(String[] args) {
        List<Employee> employeeList = ListUtil.packEmployeeList();

        // 过滤 性别为男(1)  的条数
        long total = employeeList.stream().filter((employee) -> employee.getSex().equals(1)).count();
        // 5条
        System.out.println(total);

        // 过滤 性别为男(1) 的列表
        List<Employee> filterList = employeeList.stream().filter(person -> person.getSex().equals(1)).collect(Collectors.toList());
        filterList.forEach(employee -> {

        });
    }
}

相关文章

网友评论

    本文标题:3 List过滤(filter)

    本文链接:https://www.haomeiwen.com/subject/jpxkictx.html