Skip to content

Commit 905610d

Browse files
committed
Refactored streams
1 parent 2f39a09 commit 905610d

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

concepts/streams/about.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
# About
1+
# About Streams
22

3-
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.
3+
**Streams** are a functional abstraction for processing sequences of data in Java.
4+
Unlike collections like [`List`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html), a [`Stream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/stream/Stream.html) does not store elements—it describes a pipeline of operations to transform or compute data.
45

5-
Streams are built on three key components:
6+
Streams are typically created from collections, arrays, or manually using `Stream.of(...)`.
67

7-
1. **Source** – Typically a collection like a `List` or `Set`.
8-
2. **Intermediate Operations** – Transformations such as `filter`, `map`, or `sorted`.
9-
3. **Terminal Operation** – Produces a result, like `collect`, `count`, or `forEach`.
8+
For example:
109

1110
```java
12-
List<String> names = List.of("Dharshini", "Naveen", "Selena");
13-
14-
List<String> filtered = names.stream()
15-
.filter(name -> name.startsWith("N"))
16-
.collect(Collectors.toList());
17-
18-
// => ["Naveen"]
11+
Stream<String> emptyStream = Stream.of();
12+
Stream<Integer> singleInteger = Stream.of(1);
13+
Stream<Boolean> threeBooleans = Stream.of(true, false, true);
14+
Stream<Object> mixedTypes = Stream.of("hello", 1, true); // allowed in Stream<Object>
1915
```
2016

2117

22-
[Java Stream API Overview]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html
23-
[Collectors Class]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html
24-
[Java Functional Programming with Streams]:https://www.baeldung.com/java-8-streams
18+
[Java Stream API Overview]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/package-summary.html
19+
[Collectors Class]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html
20+
[Stream Interface Documentation]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html
2521
[Stream Operations Explained]:https://www.geeksforgeeks.org/stream-in-java/

concepts/streams/introduction.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Introduction
1+
# Introduction to Streams
22

3-
Imagine you’re at an airport, watching suitcases glide past on a conveyor belt.
4-
You don’t grab every bag—you scan for yours, maybe sort by color or tag, and pick only what you need.
5-
That’s how Java Streams work.
3+
**Streams** are part of Java’s functional programming toolkit. They allow you to process collections in a declarative style—focusing on *what* to do, not *how* to do it.
64

7-
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.
5+
You can create streams from collections like `List`, `Set`, or arrays, and then apply operations like `filter`, `map`, and `reduce` to transform or analyze the data.
86

9-
Streams are part of Java’s functional programming toolkit. They help you write code that’s:
10-
- **Declarative** – Focused on intent, not mechanics.
11-
- **Composable** – Easy to chain operations.
12-
- **Lazy** – Efficient by computing only when needed.
13-
14-
Once you start using streams, you’ll find yourself writing fewer loops and more elegant pipelines. It’s not just cleaner—it’s fun.
7+
## Examples
158

9+
### Filtering a List
10+
```java
11+
List<String> names = List.of("Akash", "James", "Charles");
12+
List<String> filtered = names.stream()
13+
.filter(name -> name.startsWith("A"))
14+
.collect(Collectors.toList());
15+
// filtered is ["Akash"]

concepts/streams/links.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[
22
{
3-
"url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html",
3+
"url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/package-summary.html",
44
"description": "Java Stream API Overview"
55
},
66
{
7-
"url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html",
7+
"url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html",
88
"description": "Collectors Class"
99
},
1010
{
11-
"url": "https://www.baeldung.com/java-8-streams",
12-
"description": "Java Functional Programming with Streams"
11+
"url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html",
12+
"description": "Stream Interface Documentation"
1313
},
1414
{
1515
"url": "https://www.geeksforgeeks.org/stream-in-java/",

0 commit comments

Comments
 (0)