-
-
Notifications
You must be signed in to change notification settings - Fork 724
feat: add streams concept #2983
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
391de7b
6e1e37c
2f39a09
905610d
f0ed08e
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,6 @@ | ||
{ | ||
"blurb": "Java Streams provide a powerful way to process collections using a functional approach.", | ||
"authors": ["Navaneedan S"], | ||
"contributors": [] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# About Streams | ||
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. The about is missing the information contained in the introduction (e.g. being able to get a stream with The I also recommend looking at existing concepts and their |
||
|
||
**Streams** are a functional abstraction for processing sequences of data in Java. | ||
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. | ||
|
||
Streams are typically created from collections, arrays, or manually using `Stream.of(...)`. | ||
|
||
For example: | ||
|
||
```java | ||
Stream<String> emptyStream = Stream.of(); | ||
Stream<Integer> singleInteger = Stream.of(1); | ||
Stream<Boolean> threeBooleans = Stream.of(true, false, true); | ||
Stream<Object> mixedTypes = Stream.of("hello", 1, true); // allowed in Stream<Object> | ||
``` | ||
|
||
|
||
Check failure on line 17 in concepts/streams/about.md
|
||
[Java Stream API Overview]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/package-summary.html | ||
Check failure on line 18 in concepts/streams/about.md
|
||
[Collectors Class]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html | ||
Check failure on line 19 in concepts/streams/about.md
|
||
[Stream Interface Documentation]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html | ||
Check failure on line 20 in concepts/streams/about.md
|
||
[Stream Operations Explained]:https://www.geeksforgeeks.org/stream-in-java/ | ||
Check failure on line 21 in concepts/streams/about.md
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Introduction to Streams | ||
|
||
**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. | ||
|
||
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. | ||
|
||
## Examples | ||
|
||
### Filtering a List | ||
Check failure on line 9 in concepts/streams/introduction.md
|
||
```java | ||
Check failure on line 10 in concepts/streams/introduction.md
|
||
List<String> names = List.of("Akash", "James", "Charles"); | ||
List<String> filtered = names.stream() | ||
.filter(name -> name.startsWith("A")) | ||
.collect(Collectors.toList()); | ||
// filtered is ["Akash"] | ||
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. Wasn't sure if this is still a work in progress - the closing triple backticks are missing 😅. If not, I think it would be great to have examples for |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/package-summary.html", | ||
"description": "Java Stream API Overview" | ||
}, | ||
{ | ||
"url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html", | ||
"description": "Collectors Class" | ||
}, | ||
{ | ||
"url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html", | ||
"description": "Stream Interface Documentation" | ||
}, | ||
{ | ||
"url": "https://www.geeksforgeeks.org/stream-in-java/", | ||
"description": "Stream Operations Explained" | ||
} | ||
] |
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.
For Exercism to award you reputation points, this should be your Github username
navaneedan07
.