Most Frequently asked Java Streams coding questions - Part 1

Most Frequently asked Java Streams coding questions - Part 1

Hey Guys,

Welcome back to my blog.

Today I'm going to share few Java Streams coding questions that are asked frequently for a Java developer.

Input - 1

Assume you are given a list of numbers like {1,7,8,9,5,2,36,4,78,222,24,9}

List<Integer> list = Arrays.asList(1,7,8,9,5,2,36,4,78,222,24,9);

Questions

  1. Given a list of numbers, return the sum of all numbers.

  2. Given a list of numbers, return the average of all numbers.

  3. Given a list of numbers, square them and filter the numbers which are greater 100 and then find the average of them.

  4. Given a list of numbers, return the even and odd numbers separately.

  5. Given a list of numbers, find out all the numbers starting with 2.

  6. Given a list of numbers, print the duplicate numbers.

  7. Given a list of numbers, print the maximum and minimum values.

  8. Given a list of numbers, sort them in ASC and DESC order and print.

  9. Given a list of numbers, return the first 5 elements and their sum.

  10. Given a list of numbers, skip first 5 numbers and return the sum of remaining numbers.

  11. Given a list of numbers, return the cube of each number.

Input - 2

Given an Employee class which consists below properties. There will be list of employees who works for a single organization but in different departments.

emp_id,
emp_name,
emp_age,
emp_gender,
emp_dept,
emp_doj,
emp_salary

Questions

  1. How many male and female employees are there in the organization?

  2. Print the name of all departments in the organization.

  3. What is the average age of male and female employees?

  4. Get the details of highest paid employee in the organization.

  5. Get the names of all employees who have joined after 2015.

  6. Count the number of employees in each department.

  7. What is the average salary of each department?

  8. Who has the most working experience in the organization?

  9. Get the details of youngest male employee in the each department.

  10. What is the average salary and total salary of the whole organization?

  11. Separate the employees who are younger or equal to 25 years from those employees who are older than 25 years.

  12. Who is the oldest employee in the organization? What is his age and which department he belongs to?

  13. Find the second highest salary employee details.

  14. Get the maximum salary of an employee from each department.

  15. Get the employees count working in each department.

In coming blogs I will provide solutions for above all questions

Answers for input - 1 questions

Answers for input - 2 questions

You can follow me at LinkedIn

Thanks for reading :) Happy Coding :)