LearnFrenzy
Sign in Take a free test

Streams API · Exercise 4 of 4

Streams API Streams API Programs

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Java programs that solve real data-processing tasks with streams and collectors. Write each one yourself first, then open the solution – every solution was compiled and run on Java 21, and the output shown is the real output.

Question 1 Easy

For a list of students with marks, use streams to print the class average, the toppers (marks ≥ 90), the number who failed (< 40) and the names sorted by marks descending.

Question page & discussion
Question 2 Medium

Count word frequencies in a paragraph (lower-case, letters only, ignoring a few stop words) with groupingBy/counting, and print the top 4 words (ties alphabetical).

Question page & discussion
Question 3 Medium

For each department print the head count, total and average salary and the highest-paid employee, using a single groupingBy into a TreeMap and a summary record.

Question page & discussion
Question 4 Medium

Parse access-log lines "method path status ms", then report the error rate, the slowest request, the average response time per status class (2xx/4xx/5xx) and the most requested path.

Question page & discussion
Question 5 Medium

Using IntStream, list the primes below 50, count primes below 10,000, and find the twin-prime pairs (p, p+2) below 100.

Question page & discussion
Question 6 Medium

Parse CSV lines "sku,name,category,qty,price" (skipping the header and bad rows), then print the stock value per category, items that need reordering (qty < 10) and the total inventory value.

Question page & discussion
Question 7 Hard

Customers have orders, and orders have line items. With flatMap, compute total units sold per product, revenue per customer, and the customers who bought a "Keyboard".

Question page & discussion
Question 8 Medium

For a month of daily temperatures, print summary statistics, partition the days into hot (≥ 35) and normal, list the hot day numbers, and find the longest run of hot days.

Question page & discussion
Question 9 Hard

For each product category, compute the cheapest and most expensive item in one pass using Collectors.teeing (minBy and maxBy), and print the price spread.

Question page & discussion
Question 10 Medium

Group a list of words into anagram families using groupingBy on each word's sorted letters, keep only families with 2+ words, and print them sorted by family size then key.

Question page & discussion
All exercises doneBack to Streams APIRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links