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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/java-exercises/stream/
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics