Commit 108e4b3
committed
feat(streams): demonstrate multiple ways to create streams in Java
What
- Added `Test` class in `Stream` package to showcase **stream creation techniques**:
1. From a **Collection** (`list.stream()`).
2. From an **Array** (`Arrays.stream(array)`).
3. Using **Stream.of(...)** with direct values.
4. Using **Stream.iterate(seed, unaryOperator)`** to generate a sequence (incrementing numbers).
5. Using **Stream.generate(Supplier)`** to create infinite streams with custom logic, later truncated using `.limit(...)`.
- Example cases:
- `list.stream()` → creates a stream from a list of fruits.
- `Arrays.stream(array)` → creates a stream from an array of fruits.
- `Stream.of(1, 2, 3)` → simple stream of integers.
- `Stream.iterate(0, n -> n + 1).limit(100)` → generates first 100 natural numbers.
- `Stream.generate(() -> Integer.valueOf("Hello")).limit(5)` → 1 parent 2d5139e commit 108e4b3
1 file changed
+24
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments