1Z0-809 practice question 13 of 25
Given the definition of the Emp class: public class Emp private String eName; private Integer eAge; Emp(String eN, Integer eA) { this.eName = eN…
Full set: 196 questionsThe code first filters a list of Emp objects, keeping only those whose age is greater than 50. The initial list contains employees with ages 20, 60, and 51. The filter operation s -> s.getEAge() > 50 retains the employees "John" (age 60) and "Jim" (age 51). The subsequent map operation extracts the names of these filtered employees into a new stream. Finally, forEach prints each name from the stream, separated by a space. The resulting output is "John Jim ". Note: The code in the question contains typos (New for new, map.(... for map(...)), which are assumed to be unintentional for the purpose of evaluating the stream logic.
A: This is the list of all employee names before the filter is applied. The filter agVal removes "Sam" from the stream. C: Line n1 is a syntactically correct definition of a Predicate using a lambda expression. It does not cause a compilation error. D: Assuming the typo map.(... is corrected to map(...), this line is a valid stream operation and does not cause a compilation error. The original code as written would fail here.
- Java™ Platform, Standard Edition 8 API Specification, java.util.stream.Stream. The documentation describes the filter(Predicate predicate) and map(Function mapper) intermediate operations.
- The Java™ Tutorials, "Aggregate Operations". Oracle Corporation. This tutorial provides examples of using filter, map, and forEach to process collections.
Keep practicing
Take the free 1Z0-809 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-809 practice questions
- Question 2Given: class Student { String course, name, city; public Student (String name, String cou…
- Question 3Given: class Worker extends Thread { CyclicBarrier cb; public Worker(CyclicBarrier cb) { …
- Question 4Given the code fragment: Path file = Paths.get (“courses.txt”); // line n1 Assume the cou…
- Question 5Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment: Path …
- Question 6Given the code fragment:List<String> empDetails = Arrays.asList(“100, Robin, HR”,“200, Ma…
- Question 7Given the code fragment: List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”); Pre…
