3 過濾(filter)

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 -> {

        });
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章