0

I have to write a method body of class Employee containing 3 objects and return an arraylist of employees whose attendance is greater than 70% using lambda expression.

Java

public List<Employee> findAttendance(List<Employee> emp) {
    List<Employee> l = new ArrayList<Employee>();
    l.forEach(emp -> (if(emp.getAttendance() >= 70)) {
            l.add(emp);
     });
}
StaticBeagle
  • 5,070
  • 2
  • 23
  • 34
Suhaila
  • 1
  • 1
  • 3
    Possible duplicate of https://stackoverflow.com/questions/122105/what-is-the-best-way-to-filter-a-java-collection – Thomas Martin Sep 04 '19 at 15:19
  • 1
    Possible duplicate of [What is the best way to filter a Java Collection?](https://stackoverflow.com/questions/122105/what-is-the-best-way-to-filter-a-java-collection) – Arnaud Claudel Sep 04 '19 at 15:27

1 Answers1

1
List<Employee> empsWithGoodAttendance = l.stream()
                                          .filter(e -> e.getAttendance() >= 70)
                                          .collect(Collectors.toList());
Jude Niroshan
  • 4,280
  • 8
  • 40
  • 62