This repository contains concise, commented, and well-structured Java examples that demonstrate how to use the Java Stream API for efficient and modern data processing. Each example focuses on a common data transformation or query operation — from filtering and mapping, to advanced grouping and aggregation.
-
50+ Realistic Examples
Find, filter, map, reduce, group, sort, combine, and transform data using Stream API with intuitive, idiomatic Java code. -
Educational & Practical
Each example is presented as a separate, easily understandable static method with clear naming and documentation, making it great for learning, interviews, or reference. -
Covers Core Stream API Use Cases
Including:- Filtering and searching
- Mapping and transforming
- Distinctness and deduplication
- Sorting and ordering
- Reducing, aggregating, and summarizing
- Working with objects
- Advanced grouping and partitioning
- Optional usage and null safety
- Collectors and downstream collectors
- Counting, summing, averaging, finding min/max
- Combining and joining strings or lists
- Extracting, flattening, and mapping nested structures
- Grouping and partitioning data
- Generating and processing random data
- Working with custom objects and collections
- Clone the repo:
git clone https://github.com/javadev/java-stream-api.git
- Open in your favorite IDE
- Run the main class (
App.java
) to execute all examples, or call any method independently.
- Java learners wishing to deepen practical knowledge
- Java developers needing quick reference or copy-paste solutions
- Instructors/interviewers looking for demonstration snippets
- Anyone exploring the power of functional programming in Java!
Contributions and new stream examples are welcome! Please open an issue or PR.
Let me know if you want a shorter/longer version, or want help with a README including formatting!