Java Programs›Java 8 Streams

🌊Java 8 Streams Programs

The Stream API lets you describe what a result should be instead of writing every loop by hand. These programs cover the operations that come up most in real projects and interviews, from filtering and grouping to flattening nested lists.15 programs · each with full code, output and a step-by-step explanation

Most Asked in Interviews

🔍
Intermediate
04
Combine Values Using reduce()
Folds a list of numbers into a sum, a product and a maximum with Stream.reduce.
intermediateStreams
View Program →
05
Convert a List to a Map Using Streams
Builds a map from a list with Collectors.toMap, choosing the key, value, merge rule and map type.
intermediateStreams
View Program →
06
Count Character Occurrences Using Streams
Counts how often every character appears in a word with chars(), groupingBy and counting, sorted by character.
intermediateStreams
View Program →
07
Find Average Salary by Department Using Streams
Groups employees by department and computes each department's average salary with groupingBy and averagingInt.
intermediateStreams
View Program →
08
Find Second Highest Salary Using Streams
Finds the second-highest distinct salary in a list of employees with distinct, sorted and skip.
intermediateStreams
View Program →
09
Flatten a List of Lists Using flatMap
Merges nested lists into one flat list with Stream.flatMap.
intermediateStreams
View Program →
10
Generate Sequences Using Stream.iterate()
Builds powers of two and the Fibonacci series from infinite streams with Stream.iterate and limit.
intermediateStreams
View Program →
11
Group Words by Length Using Streams
Groups a list of words into buckets keyed by word length using Collectors.groupingBy.
intermediateStreams
View Program →
12
Handle Missing Values Using Optional
Uses Optional to handle a search that may find nothing, with map, orElse and ifPresent instead of null checks.
intermediateStreams
View Program →
13
Partition a List Using partitioningBy
Splits exam marks into pass and fail lists in one pass with Collectors.partitioningBy.
intermediateStreams
View Program →
14
Sort Employees by Salary Using Streams
Orders employee objects by salary, highest first, breaking ties by name with chained comparators.
intermediateStreams
View Program →