How to replace for loop with streams in java

class Checker{
        
    void CheckingNameFromDeptCode(LinkedList<Employee1> empObj, String deptID) 
    {
            for (int i = 0; i < empObj.size(); i++) {
                if (empObj.get(i).getDeptID().equals(deptID)) {
                    System.out.println(empObj.get(i).getEmpName());
                }
            }
    }
}

This is the method I created to check for the employees for the inputed dept list. But I been told to use streams/lambda in java 8 for the iteration instead of the good old for loop I use.

Below is the main method.

import java.util.*;
public class Manager{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkedList<Employee1> employeeObj = new LinkedList<Employee1>();
        Checker empBusObj = new Checker();
        
        employeeObj.add(new Employee1("Souvik", "D1", "Development", "L1", "Kolkata"));
        employeeObj.add(new Employee1("Anirban", "D2", "HR", "L2", "Bangalore"));
        employeeObj.add(new Employee1("Joydeep", "D3", "Design", "L3", "Delhi"));
        employeeObj.add(new Employee1("Rakesh", "D2", "HR", "L4", "Pune"));
        System.out.print("Enter the choices : ");
        int ch = sc.nextInt();
        String deptInput; 
        String locInput;
        switch (ch) 
        {
            case 1:
            System.out.print("Enter the department code : ");
            deptInput = sc.next();
            deptInput = deptInput.toUpperCase();
            empBusObj.CheckingNameFromDeptCode(employeeObj, deptInput); 
            break;

Answer

Using streams code will look like this

empObj.stream().filter(obj -> {
    return obj.getDeptID().equals(deptID);
}).forEach(obj -> {
    System.out.println(obj.getEmpName());
});

Or parallelStream to a concurrent processing:

empObj.parallelStream().filter(obj -> {
    return obj.getDeptID().equals(deptID);
}).forEach(obj -> {
    System.out.println(obj.getEmpName());
});