nerdexam
Oracle

1Z0-809 · Question #124

1Z0-809 Question #124: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #124. The question stem and answer options stay visible for context.

Question

Given: public class Data { private int x; public Data(int x) { this.x = x; } public int getX() { return x; } } public class Test { public static void main(String[] args) { List<Data> list = Arrays.asList(new Data(10), new Data(20), new Data(30)); // line n1 } } Which code fragment, when inserted at line n1, enables the code to print the output 20?

Options

  • ASystem.out.println(list.stream().filter(d -> d.getX() == 20).findFirst().get().getX());
  • BSystem.out.println(list.stream().map(Data::getX).filter(d -> d == 20).findAny().get());
  • CSystem.out.println(list.stream().filter(d -> d.getX() == 20).map(Data::getX).findAny().get());
  • DSystem.out.println(list.stream().map(Data::getX).filter(d -> d == 20).findFirst().get());

Unlock 1Z0-809 to see the answer

You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 1Z0-809 Practice