Can you explain filter and collectors in java 8 ?
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers

 Q1. Can you explain filter and collectors in java 8 ?Core Java
Ans. Filters are used to filter object in stream on certain criteria.
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collectors  filters  java 8


Related Questions

 What are we doing here

list.stream().collect(Collectors.groupingBy(ClassA::getElement1,
               Collectors.averagingDouble(ClassA::getelement2)));
 What will the following code return

list.stream().collect(Collectors.groupingBy(ClassA::getElement1,
               Collectors.averagingDouble(ClassA::getElement2)));



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: