Commit 9094b77
committed
docs(streams): add beginner-friendly explanation of Java Streams with examples
What
- Added a concise overview of **Streams in Java**:
- Definition: a way to process collections (List, Set, Map) in a pipeline style.
- Workflow:
1. Create → from a collection (`list.stream()`).
2. Process → apply intermediate ops (`filter`, `map`, `sorted`).
3. Output → use terminal ops (`forEach`, `collect`, `count`).
- Classified operations into:
* Intermediate (lazy) → filter(), map(), sorted().
* Terminal (eager) → forEach(), collect(), count().
- Included a reference table summarizing common operations with their type and purpose.
- Added **simple code examples**:
1. **Filter Example**
- Filters even numbers from a list.
```java
numbers.stream()
.filter(n -> n % 2 == 0)
.forEach(System.out::println);
```
✅ Output: `2, 4`.
2. **Map Example**
- Squares each number from a list.
```java
numbers.stream()
.map(n -> n * n)
.forEach(System.out::println);
```
✅ Output: `1, 4, 9`.
3. **Parallel Stream Example**
- Demonstrated `.parallelStream()` for concurrent processing of elements in large datasets.
Why
- This update provides a **beginner-friendly, high-level introduction** to Streams, focusing on clarity and simplicity.
- Helps newcomers understand **what a stream is, how the workflow looks, and what common operations exist** before diving into advanced topics.
- Examples illustrate functional-style coding, replacing verbose loops with declarative pipelines.
Logic
1. **Stream = pipeline abstraction** over a collection.
2. **Intermediate ops** describe *what transformations to apply* but execute lazily.
3. **Terminal ops** trigger the pipeline and produce results.
4. **Parallel streams** leverage multi-core processors automatically for large independent workloads.
5. Provides **cleaner, faster, more maintainable code** compared to imperative loops.
Key Takeaways
✔ Stream = sequence of elements processed in a pipeline.
✔ Workflow = Create → Process → Output.
✔ Intermediate = lazy, Terminal = eager.
✔ Common ops = filter, map, sorted, forEach, collect, count.
✔ Parallel streams = automatic concurrency for big datasets.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent ac95e09 commit 9094b77
File tree
1 file changed
+6
-14
lines changed- Java 8 Crash Course/Java 8 Streams/src
1 file changed
+6
-14
lines changedLines changed: 6 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 1 | + | |
6 | 2 | | |
7 | 3 | | |
8 | 4 | | |
| |||
12 | 8 | | |
13 | 9 | | |
14 | 10 | | |
15 | | - | |
| 11 | + | |
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
19 | 15 | | |
20 | 16 | | |
21 | 17 | | |
22 | | - | |
23 | | - | |
| 18 | + | |
24 | 19 | | |
25 | 20 | | |
26 | 21 | | |
| |||
32 | 27 | | |
33 | 28 | | |
34 | 29 | | |
35 | | - | |
| 30 | + | |
36 | 31 | | |
37 | 32 | | |
38 | 33 | | |
| |||
42 | 37 | | |
43 | 38 | | |
44 | 39 | | |
45 | | - | |
46 | 40 | | |
47 | 41 | | |
48 | 42 | | |
49 | | - | |
50 | 43 | | |
51 | 44 | | |
52 | 45 | | |
| |||
55 | 48 | | |
56 | 49 | | |
57 | 50 | | |
58 | | - | |
59 | 51 | | |
60 | 52 | | |
61 | 53 | | |
62 | 54 | | |
63 | | - | |
| 55 | + | |
64 | 56 | | |
65 | 57 | | |
66 | 58 | | |
67 | 59 | | |
68 | 60 | | |
69 | 61 | | |
70 | | - | |
| 62 | + | |
0 commit comments