-
-
Notifications
You must be signed in to change notification settings - Fork 737
Add new Streams concept with intro and resources #3041
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,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. | ||
|
|
||
| --- | ||
|
|
||
| ### 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
Member
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. This content is incomplete |
||
| 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 | ||
| } |
| 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. | ||
|
|
||
|
Member
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 think this is also missing how to get a |
||
| 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")) | ||
|
Contributor
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 would introduce, as an intermediate operation:
And Termination operations:
Member
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 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.
Contributor
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. agree. I would think that at least the collect and findfirst or anyMatch should be introduced:
|
||
| .map(String::toUpperCase) | ||
| .forEach(System.out::println); | ||
| } | ||
| } | ||
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.
I would also introduce the intermediate and terminal methods to introduce the possiblity of chaining function.