🌊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
Find Second Highest Salary Using Streams
beginnerFilter Even Numbers Using Streams
intermediateGroup Words by Length Using Streams
intermediateFind Average Salary by Department Using Streams
intermediateCount Character Occurrences Using Streams
intermediateConvert a List to a Map Using Streams
intermediateFlatten a List of Lists Using flatMap
intermediateSort Employees by Salary Using Streams
🔍
Beginner
01
View Program →Filter Even Numbers Using Streams
Keeps only the even values from a list with Stream.filter and collects them into a new list.
beginnerStreams
02
View Program →Find Sum and Average Using Streams
Totals and averages a list of scores with mapToInt, sum and average on an IntStream.
beginnerStreams
03
View Program →Join Strings Using Collectors.joining()
Combines a list of strings into one with Collectors.joining, using a separator, prefix and suffix.
beginnerStreams
Intermediate
04
View Program →Combine Values Using reduce()
Folds a list of numbers into a sum, a product and a maximum with Stream.reduce.
intermediateStreams
05
View Program →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
06
View Program →Count Character Occurrences Using Streams
Counts how often every character appears in a word with chars(), groupingBy and counting, sorted by character.
intermediateStreams
07
View Program →Find Average Salary by Department Using Streams
Groups employees by department and computes each department's average salary with groupingBy and averagingInt.
intermediateStreams
08
View Program →Find Second Highest Salary Using Streams
Finds the second-highest distinct salary in a list of employees with distinct, sorted and skip.
intermediateStreams
09
View Program →Flatten a List of Lists Using flatMap
Merges nested lists into one flat list with Stream.flatMap.
intermediateStreams
10
View Program →Generate Sequences Using Stream.iterate()
Builds powers of two and the Fibonacci series from infinite streams with Stream.iterate and limit.
intermediateStreams
11
View Program →Group Words by Length Using Streams
Groups a list of words into buckets keyed by word length using Collectors.groupingBy.
intermediateStreams
12
View Program →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
13
View Program →Partition a List Using partitioningBy
Splits exam marks into pass and fail lists in one pass with Collectors.partitioningBy.
intermediateStreams
14
View Program →Sort Employees by Salary Using Streams
Orders employee objects by salary, highest first, breaking ties by name with chained comparators.
intermediateStreams