Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 181

Given the definition of the Emp class:

public class Emp

private String eName;

private Integer eAge;

Emp(String eN, Integer eA) {

this.eName = eN;

this.eAge = eA;

}

public Integer getEAge () {return eAge;}

public String getEName () {return eName;}

}

and code fragment:

Listli = Arrays.asList(new Emp("Sam", 20), New Emp("John", 60), New Emp("Jim", 51));

Predicate agVal = s -> s.getEAge() <= 60; //line n1 li = li.stream().filter(agVal).collect(Collectors.toList());

Stream names = li.stream()map.(Emp::getEName); //line n2 names.forEach(n -> System.out.print(n + " "));

What is the result?

    Correct Answer: A

    The code initializes a list of Emp objects and then filters them based on their age, keeping those with age less than or equal to 60. Then, it maps this filtered list to their names and prints each name. As all the entries in the given list meet the condition of having age less than or equal to 60, the resulting output will be 'Sam John Jim'. The typos in the original question's provided code must be corrected (e.g., 'New' should be 'new' and 'map.' should be '.map') for this to compile and run successfully. If these corrections are made, the correct answer is 'Sam John Jim'.

Discussion
Svetleto13Option: A

A,tested after corrected all typos.

steefaandOption: A

A assuming all typos are corrected.

jduarteOption: A

Sorry, response is A if change Arrays.asList(new Emp("Sam", 20), new Emp("John", 60), new Emp("Jim", 51)); and Stream<String> names = li.stream().map(Emp::getEName);

jduarteOption: B

Answer B. Test. the sentence Stream<String> names = li.stream()map.(Emp::getEName); should be Stream<String> names = li.stream().map(Emp::getEName); . as well New is lower case

maslac

Answer is A. Notice condition in Predicate<Emp> agVal = s -> s.getEAge() <= 60 which results in filtering all elements in list