-
-
Notifications
You must be signed in to change notification settings - Fork 719
feat: add streams concept #2983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"blurb": "Java Streams provide a powerful way to process collections using a functional approach.", | ||
"authors": ["Navaneedan"], | ||
"contributors": [] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# About | ||
|
||
Streams in Java offer a modern, functional approach to processing data. Instead of writing verbose loops, you can build pipelines that transform collections with clarity and elegance. | ||
|
||
Streams are built on three key components: | ||
|
||
1. **Source** – Typically a collection like a `List` or `Set`. | ||
2. **Intermediate Operations** – Transformations such as `filter`, `map`, or `sorted`. | ||
3. **Terminal Operation** – Produces a result, like `collect`, `count`, or `forEach`. | ||
|
||
```java | ||
List<String> names = List.of("Dharshini", "Naveen", "Selena"); | ||
|
||
List<String> filtered = names.stream() | ||
.filter(name -> name.startsWith("N")) | ||
.collect(Collectors.toList()); | ||
|
||
// => ["Naveen"] | ||
``` | ||
|
||
|
||
[Java Stream API Overview]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html | ||
[Collectors Class]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html | ||
[Java Functional Programming with Streams]:https://www.baeldung.com/java-8-streams | ||
[Stream Operations Explained]:https://www.geeksforgeeks.org/stream-in-java/ |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||
# Introduction | ||||||||||
|
||||||||||
Imagine you’re at an airport, watching suitcases glide past on a conveyor belt. You don’t grab every bag—you scan for yours, maybe sort by color or tag, and pick only what you need. That’s how Java Streams work. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the use of the analogy! Just one thing - each sentence should be on a new line (see our paragraph specification).
Suggested change
|
||||||||||
|
||||||||||
Instead of writing loops and mutating variables, you describe *what* you want to do with the data. Want to filter out expensive items? Map names to uppercase? Count how many entries match a condition? Streams make it all feel natural. | ||||||||||
|
||||||||||
Streams are part of Java’s functional programming toolkit. They help you write code that’s: | ||||||||||
- **Declarative** – Focused on intent, not mechanics. | ||||||||||
- **Composable** – Easy to chain operations. | ||||||||||
- **Lazy** – Efficient by computing only when needed. | ||||||||||
|
||||||||||
Once you start using streams, you’ll find yourself writing fewer loops and more elegant pipelines. It’s not just cleaner—it’s fun. | ||||||||||
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid promoting streams over for loops here. Generally, the introduction should focus on how to use streams (see introducton.md docs), not what they offer. I'd recommend having a look at existing concept introductions like lists, datetime or randomness. |
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The track targets Java 21 and older, but these links are specifically for Java 8. Have there been any significant changes to this package since 8? |
||
"description": "Java Stream API Overview" | ||
}, | ||
{ | ||
"url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html", | ||
"description": "Collectors Class" | ||
}, | ||
{ | ||
"url": "https://www.baeldung.com/java-8-streams", | ||
"description": "Java Functional Programming with Streams" | ||
}, | ||
{ | ||
"url": "https://www.geeksforgeeks.org/stream-in-java/", | ||
"description": "Stream Operations Explained" | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, the about.md follows the introduction.md, although it can also have more information. See the about.md documentation or the lists, datetime or randomness for examples.