Java Stream - Exercises, Practice, Solutions
Java Streams Exercises [ 8 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
Processing Data with Java SE 8 Streams:
Stream is a sequence of elements from a source that supports aggregate operations. Let’s break it down:
- Sequence of elements: A stream provides an interface to a sequenced set of values of a specific element type. However, streams don’t actually store elements; they are computed on demand.
- Source: Streams consume from a data-providing source such as collections, arrays, or I/O resources.
- Aggregate operations: Streams support SQL-like operations and common operations from functional programing languages, such as filter, map, reduce, find, match, sorted, and so on.
1. Write a Java program to calculate the average of a list of integers using streams.
2. Write a Java program to convert a list of strings to uppercase or lowercase using streams.
3. Write a Java program to calculate the sum of all even, odd numbers in a list using streams.
4. Write a Java program to remove all duplicate elements from a list using streams.
5. Write a Java program to count the number of strings in a list that start with a specific letter using streams.
6. Write a Java program to sort a list of strings in alphabetical order, ascending and descending using streams.
7. Write a Java program to find the maximum and minimum values in a list of integers using streams.
8. Write a Java program to find the second smallest and largest elements in a list of integers using streams.
Java Code Editor
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
Java: Tips of the Day
GenerateRandomInt
Generate a random integer between Integer.MIN_VALUE and Integer.MAX_VALUE.
public static int generateRandomInt() { return ThreadLocalRandom.current().nextInt(); }
Ref: https://bit.ly/3keywpH
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook