Java OCA OCP Practice Question 1573

Question

Which method is available on both List and Stream implementations?

  • A. filter()
  • B. forEach()
  • C. replace()
  • D. sort()


B.

Note

Option A is incorrect because the filter() method is available on Stream, but not List.

Option C is incorrect because the replace() method is available on List, but not Stream.

Option D is tricky because there is a sort() method on List and a sorted() method on Stream.

These are different method names though, so Option D is incorrect.

Option B is the answer because both interfaces have a forEach() method.




PreviousNext

Related