Java - Interview Questions and Answers for 'Collector' | Search Java Interview Question -

Search Java Interview Questions

 2280 questions in repository.
 There are more than 200 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 for 'Collector' - 2 question(s) found - Order By Newest

 Q1. Write a Program that gets a set of numbers , filters out the non prime numbers , calculate the factorial of each prime number and then finds the average of all factorials using Lambda expressions2017-05-14 14:02:57

Ans. public class BuggyBread1 {
   public static void main(String args[]) {
      // Declare and Initialize the Collection
      Set<Integer> intSet = new HashSet<Integer>();

      // Add Elements

      double averageOfNonPrimeFactorials =>checkIfPrime(p)).collect(Collectors.averagingInt(p->calculateFactorial(p)));
      System.out.println(averageOfNonPrimeFactorials );
   static private boolean checkIfPrime(int num){
      for(int count=2;count < num;count++){
         if(num % count == 0){
            return false;
      return true;
   static private int calculateFactorial(int num){
      int factorial = 1;
      for(int count=num;count > 0;count--){
         factorial = factorial * count;
      return factorial;

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

   Like      Discuss      Correct / Improve     java 8  lambda expressions  lambda  filter  Collectors  factorial  prime number

Related Questions

  What is a Lambda Expression ? What's its use ?
  Difference between final and effectively final ? Why is effectively final even required ?
  Difference between Predicate, Supplier and Consumer ?
  What does the following lambda expression means ?
  Difference between DoubleSummaryStatistics , IntSummaryStatistics and LongSummaryStatistics ?
 What is the use of :: operator wef from Java 8 ?
 What is a method reference in Java ?
 What is Lambda Calculus ?
 Lets say we have a set "set1" with objects of Class A, Class has a non static string called element1, Write a code ( using lambda expression ) to see if there is any object in the set with element1 = "Hello".
 Given a collection of Employee objects, how can we get the customers with name starting with 'A' using lambda expression.

 Q2. Write a class / program that takes few numbers from the input and then output the average ?Core Java2017-01-27 14:26:00

Ans. public class Class{
   public static void main(String[] args){
      List<Integer> collector = new ArrayList();

      Scanner scanner = new Scanner(;
      int x = scanner.nextInt();
      while(x != 0){
         x = scanner.nextInt();

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

   Like      Discuss      Correct / Improve     coding  code  collector  streams  Collectors.average     Raytheon

Related Questions

  What is a stream and what are the types of Streams and classes of the Streams?
 Explain System.out.println ?
  What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
  Which class is used to read streams of characters from a file?
  Which class is used to read streams of raw bytes from a file?
 How Spliterator in Java 8 different than iterator ?
 Which is better in terms of performance - Iterator or Spliterator ?
 Difference between System.out.printf and System.out.println ?
 What is the difference between the Reader/Writer hierarchy and the Stream class hierarchy?
 Why is it important to close files and streams ?

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner

comments powered by Disqus

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:

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   

Questions Asked: