From 391de7b763991dce0935d4f83f683658acda869c Mon Sep 17 00:00:00 2001 From: navaneedan07 Date: Sun, 17 Aug 2025 22:05:45 +0530 Subject: [PATCH 1/5] feat(concepts): add Streams concept with blurb and authorship metadata --- concepts/streams/.meta/config.json | 5 +++++ concepts/streams/about.md | 25 +++++++++++++++++++++++++ concepts/streams/introduction.md | 13 +++++++++++++ concepts/streams/links.json | 18 ++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 concepts/streams/.meta/config.json create mode 100644 concepts/streams/about.md create mode 100644 concepts/streams/introduction.md create mode 100644 concepts/streams/links.json diff --git a/concepts/streams/.meta/config.json b/concepts/streams/.meta/config.json new file mode 100644 index 000000000..34a5a43ab --- /dev/null +++ b/concepts/streams/.meta/config.json @@ -0,0 +1,5 @@ +{ + "blurb": "Java Streams provide a powerful way to process collections using a functional approach.", + "authors": ["Navaneedan"], + "contributors": [] +} diff --git a/concepts/streams/about.md b/concepts/streams/about.md new file mode 100644 index 000000000..419119fa1 --- /dev/null +++ b/concepts/streams/about.md @@ -0,0 +1,25 @@ +# About + +Streams in Java offer a modern, functional approach to processing data. Instead of writing verbose loops, you can build pipelines that transform collections with clarity and elegance. + +Streams are built on three key components: + +1. **Source** – Typically a collection like a `List` or `Set`. +2. **Intermediate Operations** – Transformations such as `filter`, `map`, or `sorted`. +3. **Terminal Operation** – Produces a result, like `collect`, `count`, or `forEach`. + +```java +List names = List.of("Dharshini", "Naveen", "Selena"); + +List filtered = names.stream() + .filter(name -> name.startsWith("N")) + .collect(Collectors.toList()); + +// => ["Naveen"] +``` + + +[Java Stream API Overview]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html +[Collectors Class]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html +[Java Functional Programming with Streams]:https://www.baeldung.com/java-8-streams +[Stream Operations Explained]:https://www.geeksforgeeks.org/stream-in-java/ diff --git a/concepts/streams/introduction.md b/concepts/streams/introduction.md new file mode 100644 index 000000000..7b9f1da4e --- /dev/null +++ b/concepts/streams/introduction.md @@ -0,0 +1,13 @@ +# Introduction + +Imagine you’re at an airport, watching suitcases glide past on a conveyor belt. You don’t grab every bag—you scan for yours, maybe sort by color or tag, and pick only what you need. That’s how Java Streams work. + +Instead of writing loops and mutating variables, you describe *what* you want to do with the data. Want to filter out expensive items? Map names to uppercase? Count how many entries match a condition? Streams make it all feel natural. + +Streams are part of Java’s functional programming toolkit. They help you write code that’s: +- **Declarative** – Focused on intent, not mechanics. +- **Composable** – Easy to chain operations. +- **Lazy** – Efficient by computing only when needed. + +Once you start using streams, you’ll find yourself writing fewer loops and more elegant pipelines. It’s not just cleaner—it’s fun. + diff --git a/concepts/streams/links.json b/concepts/streams/links.json new file mode 100644 index 000000000..b9a22cf8a --- /dev/null +++ b/concepts/streams/links.json @@ -0,0 +1,18 @@ +[ + { + "url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html", + "description": "Java Stream API Overview" + }, + { + "url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html", + "description": "Collectors Class" + }, + { + "url": "https://www.baeldung.com/java-8-streams", + "description": "Java Functional Programming with Streams" + }, + { + "url": "https://www.geeksforgeeks.org/stream-in-java/", + "description": "Stream Operations Explained" + } +] From 6e1e37c87dc362d21d718447b955bea128c9db90 Mon Sep 17 00:00:00 2001 From: navaneedan07 Date: Sun, 17 Aug 2025 22:08:29 +0530 Subject: [PATCH 2/5] feat(concepts): add Streams concept --- concepts/streams/.meta/config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/concepts/streams/.meta/config.json b/concepts/streams/.meta/config.json index 34a5a43ab..90a9cb3e5 100644 --- a/concepts/streams/.meta/config.json +++ b/concepts/streams/.meta/config.json @@ -3,3 +3,4 @@ "authors": ["Navaneedan"], "contributors": [] } + From 2f39a09b8286c166fc192b0e47867bbea6dd2aa0 Mon Sep 17 00:00:00 2001 From: Navaneedan S Date: Tue, 26 Aug 2025 21:38:58 +0530 Subject: [PATCH 3/5] Update concepts/streams/introduction.md Co-authored-by: Kah Goh --- concepts/streams/introduction.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/concepts/streams/introduction.md b/concepts/streams/introduction.md index 7b9f1da4e..3a47f0006 100644 --- a/concepts/streams/introduction.md +++ b/concepts/streams/introduction.md @@ -1,6 +1,8 @@ # Introduction -Imagine you’re at an airport, watching suitcases glide past on a conveyor belt. You don’t grab every bag—you scan for yours, maybe sort by color or tag, and pick only what you need. That’s how Java Streams work. +Imagine you’re at an airport, watching suitcases glide past on a conveyor belt. +You don’t grab every bag—you scan for yours, maybe sort by color or tag, and pick only what you need. +That’s how Java Streams work. Instead of writing loops and mutating variables, you describe *what* you want to do with the data. Want to filter out expensive items? Map names to uppercase? Count how many entries match a condition? Streams make it all feel natural. From 905610d0684c31af27455fbae98417d99315f812 Mon Sep 17 00:00:00 2001 From: navaneedan07 Date: Tue, 26 Aug 2025 22:20:38 +0530 Subject: [PATCH 4/5] Refactored streams --- concepts/streams/about.md | 28 ++++++++++++---------------- concepts/streams/introduction.md | 22 +++++++++++----------- concepts/streams/links.json | 8 ++++---- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/concepts/streams/about.md b/concepts/streams/about.md index 419119fa1..5946ef0a7 100644 --- a/concepts/streams/about.md +++ b/concepts/streams/about.md @@ -1,25 +1,21 @@ -# About +# About Streams -Streams in Java offer a modern, functional approach to processing data. Instead of writing verbose loops, you can build pipelines that transform collections with clarity and elegance. +**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 built on three key components: +Streams are typically created from collections, arrays, or manually using `Stream.of(...)`. -1. **Source** – Typically a collection like a `List` or `Set`. -2. **Intermediate Operations** – Transformations such as `filter`, `map`, or `sorted`. -3. **Terminal Operation** – Produces a result, like `collect`, `count`, or `forEach`. +For example: ```java -List names = List.of("Dharshini", "Naveen", "Selena"); - -List filtered = names.stream() - .filter(name -> name.startsWith("N")) - .collect(Collectors.toList()); - -// => ["Naveen"] +Stream emptyStream = Stream.of(); +Stream singleInteger = Stream.of(1); +Stream threeBooleans = Stream.of(true, false, true); +Stream mixedTypes = Stream.of("hello", 1, true); // allowed in Stream ``` -[Java Stream API Overview]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html -[Collectors Class]:https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html -[Java Functional Programming with Streams]:https://www.baeldung.com/java-8-streams +[Java Stream API Overview]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/package-summary.html +[Collectors Class]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html +[Stream Interface Documentation]:https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html [Stream Operations Explained]:https://www.geeksforgeeks.org/stream-in-java/ diff --git a/concepts/streams/introduction.md b/concepts/streams/introduction.md index 3a47f0006..39b52e489 100644 --- a/concepts/streams/introduction.md +++ b/concepts/streams/introduction.md @@ -1,15 +1,15 @@ -# Introduction +# Introduction to Streams -Imagine you’re at an airport, watching suitcases glide past on a conveyor belt. -You don’t grab every bag—you scan for yours, maybe sort by color or tag, and pick only what you need. -That’s how Java Streams work. +**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. -Instead of writing loops and mutating variables, you describe *what* you want to do with the data. Want to filter out expensive items? Map names to uppercase? Count how many entries match a condition? Streams make it all feel natural. +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. -Streams are part of Java’s functional programming toolkit. They help you write code that’s: -- **Declarative** – Focused on intent, not mechanics. -- **Composable** – Easy to chain operations. -- **Lazy** – Efficient by computing only when needed. - -Once you start using streams, you’ll find yourself writing fewer loops and more elegant pipelines. It’s not just cleaner—it’s fun. +## Examples +### Filtering a List +```java +List names = List.of("Akash", "James", "Charles"); +List filtered = names.stream() + .filter(name -> name.startsWith("A")) + .collect(Collectors.toList()); +// filtered is ["Akash"] diff --git a/concepts/streams/links.json b/concepts/streams/links.json index b9a22cf8a..195beba1e 100644 --- a/concepts/streams/links.json +++ b/concepts/streams/links.json @@ -1,15 +1,15 @@ [ { - "url": "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html", + "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/javase/8/docs/api/java/util/stream/Collectors.html", + "url": "https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html", "description": "Collectors Class" }, { - "url": "https://www.baeldung.com/java-8-streams", - "description": "Java Functional Programming with Streams" + "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/", From f0ed08eedd9641717717e788e39523521e3652dc Mon Sep 17 00:00:00 2001 From: navaneedan07 Date: Tue, 26 Aug 2025 22:32:25 +0530 Subject: [PATCH 5/5] Refactored streams --- concepts/streams/.meta/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/concepts/streams/.meta/config.json b/concepts/streams/.meta/config.json index 90a9cb3e5..2647638dd 100644 --- a/concepts/streams/.meta/config.json +++ b/concepts/streams/.meta/config.json @@ -1,6 +1,6 @@ { "blurb": "Java Streams provide a powerful way to process collections using a functional approach.", - "authors": ["Navaneedan"], + "authors": ["Navaneedan S"], "contributors": [] }