diff --git a/concepts/streams/.meta/config.json b/concepts/streams/.meta/config.json new file mode 100644 index 000000000..2647638dd --- /dev/null +++ b/concepts/streams/.meta/config.json @@ -0,0 +1,6 @@ +{ + "blurb": "Java Streams provide a powerful way to process collections using a functional approach.", + "authors": ["Navaneedan S"], + "contributors": [] +} + diff --git a/concepts/streams/about.md b/concepts/streams/about.md new file mode 100644 index 000000000..5946ef0a7 --- /dev/null +++ b/concepts/streams/about.md @@ -0,0 +1,21 @@ +# About Streams + +**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 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/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 new file mode 100644 index 000000000..39b52e489 --- /dev/null +++ b/concepts/streams/introduction.md @@ -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 +```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 new file mode 100644 index 000000000..195beba1e --- /dev/null +++ b/concepts/streams/links.json @@ -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" + } +]