Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers | ||||
| ||||
Ans. Filters are used to filter object in stream on certail criteria. And collector is used to collect outcome of the stream. Collector is a terminal operation. List numbers = List.of(1,2,3,4,5,6,7); List evenNumbers = numbers.stream().filter(n -> n%2==0).collect(Collectors.toList()); The above code will filter out odd numbers and return the list of even number. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
![]() | ||||
![]() | ||||
![]() list.stream().collect(Collectors.groupingBy(ClassA::getElement1, Collectors.averagingDouble(ClassA::getelement2))); | ||||
![]() list.stream().collect(Collectors.groupingBy(ClassA::getElement1, Collectors.averagingDouble(ClassA::getElement2))); | ||||
![]() | ||||