exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 181 discussion

Actual exam question from Oracle's 1z0-809
Question #: 181
Topic #: 1
[All 1z0-809 Questions]

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:
List<Emp>li = Arrays.asList(new Emp("Sam", 20), New Emp("John", 60), New Emp("Jim", 51));
Predicate<Emp> agVal = s -> s.getEAge() <= 60; //line n1 li = li.stream().filter(agVal).collect(Collectors.toList());
Stream<String> names = li.stream()map.(Emp::getEName); //line n2 names.forEach(n -> System.out.print(n + " "));
What is the result?

  • A. Sam John Jim
  • B. John Jim
  • C. A compilation error occurs at line n1.
  • D. A compilation error occurs at line n2.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
steefaand
5 months, 4 weeks ago
Selected Answer: A
A assuming all typos are corrected.
upvoted 1 times
...
Svetleto13
3 years, 2 months ago
A,tested after corrected all typos.
upvoted 4 times
...
jduarte
3 years, 3 months ago
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);
upvoted 1 times
...
jduarte
3 years, 6 months ago
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
upvoted 1 times
maslac
3 years, 3 months ago
Answer is A. Notice condition in Predicate<Emp> agVal = s -> s.getEAge() <= 60 which results in filtering all elements in list
upvoted 4 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago