从java列表中提取列表值

cha*_*r.n 0 java-8 java-stream

public class FetchVarableList {

public static void main(String[] args) {

    List<List<Employee>> empsList = new ArrayList<>();

    Employee e1 = new Employee(1, "Abi", "Fin", 2000);
    Employee e2 = new Employee(2, "Chandu", "OPs", 5000);
    Employee e3 = new Employee(3, "mahesh", "HR", 8000);
    Employee e4 = new Employee(4, "Suresh", "Main", 1000);


    List<Employee> empList = new ArrayList<>();
    empList.add(e1); empList.add(e2); 


    List<Employee> empList2 = new ArrayList<>();

    empList2.add(e3); empList2.add(e4);


    empsList.add(empList);

    empsList.add(empList2);
}
Run Code Online (Sandbox Code Playgroud)

}

上面这段代码是empList2中的emp1,e3,e4中的员工e1,e2列表,这两个员工列表添加到empslist,我想在Integer的单个列表中获取所有员工号码

如何从java8中的一个列表中获取所有员工编号列表

JB *_*zet 8

List<Integer> numbers = empsList.stream()
                                .flatMap(List::stream)
                                .map(Employee::getNumber)
                                .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)