Which method is available on both List and Stream implementations?
filter()
forEach()
replace()
sort()
B.
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.