|
| 1 | +package com.eight.pipeline; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Arrays; |
| 5 | +import java.util.Iterator; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +public class EmployeeRemove { |
| 9 | + |
| 10 | + public static void main(String[] args) { |
| 11 | + // TODO: Remove an Employee from the collection |
| 12 | + |
| 13 | + List<Employee> input = getEmployeeDetails(); |
| 14 | + String target = "Somu"; |
| 15 | + |
| 16 | + System.out.println(input); |
| 17 | + |
| 18 | + /*for (Iterator iterator = input.iterator(); iterator.hasNext();) { |
| 19 | + Employee employee = (Employee) iterator.next(); |
| 20 | + if(target.equals(employee.getName())) { |
| 21 | + iterator.remove(); |
| 22 | + } |
| 23 | + }*/ |
| 24 | + |
| 25 | + input.removeIf(employee -> target.equals(employee.getName())); |
| 26 | + System.out.println(input); |
| 27 | + } |
| 28 | + |
| 29 | + private static List<Employee> getEmployeeDetails() { |
| 30 | + List<Employee> sample = new ArrayList<>(); |
| 31 | + sample.add(new Employee("Suresh", 27)); |
| 32 | + sample.add(new Employee("Melvin", 29)); |
| 33 | + sample.add(new Employee("Somu", 30)); |
| 34 | + sample.add(new Employee("Deepan", 31)); |
| 35 | + return sample; |
| 36 | + /* return Arrays.asList(new Employee("Suresh", 27), |
| 37 | + new Employee("Melvin", 29), |
| 38 | + new Employee("Somu", 30), |
| 39 | + new Employee("Deepan", 31));*/ |
| 40 | + } |
| 41 | +} |
0 commit comments