What are Streams?
•• Introduced in Java 8
• • A Stream is a sequence of elements
supporting sequential and parallel operations
• • Enables functional-style operations on
collections
• • Does not store data, but conveys elements
from a data source
3.
Stream Features
• •Declarative: Write what you want, not how
• • Can be sequential or parallel
• • Supports pipelining
• • Lazy evaluation (operations executed only
when needed)
Example: Using Streams
List<String>names = Arrays.asList("Alice", "Bob", "Charlie");
names.stream()
.filter(n -> n.startsWith("A"))
.map(String::toUpperCase)
.forEach(System.out::println);
// Output: ALICE
6.
Benefits of Streams
•• Cleaner, more readable code
• • Easier to work with collections
• • Parallel execution support
• • Reduces boilerplate iteration logic