nerdexam
Oracle

1Z0-819 · Question #112

Given: List<String> longlist = List.of("Hello", "World", "Best"); List<String> shortlist = new ArrayList<>(); Which code fragment correctly forms a short list of words containing the letter "e"?

The correct answer is C. shortlist = longlist.stream() .filter(w -> w.indexOf('e') != -1) .parallel() .collect(Collectors.toList()). See the full explanation below for the reasoning.

Question

Given: List<String> longlist = List.of("Hello", "World", "Best"); List<String> shortlist = new ArrayList<>(); Which code fragment correctly forms a short list of words containing the letter "e"?

Options

  • Alonglist.stream() .filter(w -> w.indexOf('e') != -1) .peek(shortlist::add) .forEach(w -> shortlist.add(w));
  • Blonglist.parallelStream() .filter(w -> w.indexOf('e') != -1) .forEach(w -> shortlist.add(w));
  • Cshortlist = longlist.stream() .filter(w -> w.indexOf('e') != -1) .parallel() .collect(Collectors.toList());
  • Dlonglist.stream() .filter(w -> w.indexOf('e') != -1) .parallel() .collect(shortlist);

How the community answered

(18 responses)
  • A
    6% (1)
  • B
    6% (1)
  • C
    72% (13)
  • D
    17% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice