package com.bruiser.java8;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.bruiser.java8.model.Employee;
public class EmployeeFilterDemo {
public static void main(String[] args) {
List<Employee> empList = new ArrayList<>();
Employee emp1 = new Employee(1, "Hari", "DEP1");
Employee emp2 = new Employee(2, "Sivan", "DEP2");
Employee emp3 = new Employee(3, "Vignesh", "DEP3");
Employee emp4 = new Employee(4, "Venki", "DEP1");
Employee emp5 = new Employee(5, "Arun", "DEP2");
empList.add(emp1);
empList.add(emp2);
empList.add(emp3);
empList.add(emp4);
empList.add(emp5);
List<Employee> filteredEmpList = empList.stream().filter(emp -> emp.getDeptId().equals("DEP1")).collect(Collectors.toList());
filteredEmpList.forEach(System.out::println);
}
}
Employee [id=1, name=Hari, deptId=DEP1]
Employee [id=4, name=Venki, deptId=DEP1]