Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions concepts/streams/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# About Streams

Java Streams provide a functional, declarative approach to processing collections of data.

Instead of writing explicit loops, Streams let you build **pipelines** of operations — transforming data step-by-step in a clean, readable way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also introduce the intermediate and terminal methods to introduce the possiblity of chaining function.

  • I would also introduce the usage of the lambda with only one function to execute which makes more readable

---

### Creating Streams
Streams can be created from collections, arrays, or I/O channels:
```java
List<Integer> numbers = List.of(1, 2, 3, 4, 5);
Stream<Integer> stream = numbers.stream();
Comment on lines +9 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This content is incomplete

6 changes: 6 additions & 0 deletions concepts/streams/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"blurb": "Learn how to use Java Streams for functional and declarative data processing.",
"authors": ["Zaildar_Anmol"],
"contributors": [],
"forked_from": null
}
22 changes: 22 additions & 0 deletions concepts/streams/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Introduction

The `Stream` API, introduced in Java 8, provides a modern, functional way to process data.

A **Stream** is a sequence of elements that supports operations like filtering, mapping, and reducing.
It allows you to transform and analyze collections without using traditional loops.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also missing how to get a Stream

Example:
```java
import java.util.*;
import java.util.stream.*;

public class Example {
public static void main(String[] args) {
List<String> names = List.of("Arjun", "Riya", "Sam", "Aman");

names.stream()
.filter(n -> n.startsWith("A"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would introduce, as an intermediate operation:

  • filter
  • map, mapToInt, mapToLong...
  • peek
  • limit
  • distinct
  • sorted
  • skip

And Termination operations:

  • collect
  • count
  • reduce
  • anyMatch
  • findFirst

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be good to introduce some of theses operations. Note we don't need a complete list, but having some would be great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. I would think that at least the collect and findfirst or anyMatch should be introduced:

  • Collect is one of the terminal operation that is widely used.
  • a terminal operation liike findfirst to show we can return only one element and anyMatch to show that a stream can return a boolean

.map(String::toUpperCase)
.forEach(System.out::println);
}
}