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

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() > 50; //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: D

    The code will result in a compilation error at line n2. The correct syntax for mapping a stream in Java is `li.stream().map(Emp::getEName)`, but in the provided code fragment, there is an incorrect placement of the dot in `map.(Emp::getEName)`. This syntax error results in a compilation error.

Discussion
thetechOption: B

Answer is B. Tested

DestroyerOption: B

Answer should be "John Jim"

asdfjhfgjuaDCVOption: B

B is the correct answer

steefaandOption: B

B is correct.

luchvA123Option: B

B is correct