Java Streams (C++20 Ranges)

Introduced in Java 8, the Stream API is a tool used to process sequences of elements (like collections or arrays)
Streams are specifically designed for data sources that contain multiple elements (sequences of data)
Every object in java.util does not have .stream() method.
Collections (List, Set, Queue) : HAVE .stream() method
Maps (HashMap, TreeMap, etc.): DOEST NOT HAVE .stream() method.

Example: Imagine you have a list of names and you want to find all names starting with the letter "A", convert them to uppercase, and collect them into a new list.


import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamExample {
    public static void main(String[] args) {
        List names = Arrays.asList("Alice", "Bob", "Charlie", "Amanda", "Brian");

        // Using Java Streams
        List result = names.stream()
                .filter(name -> name.startsWith("A")) // Intermediate operation
                .map(String::toUpperCase)             // Intermediate operation
                .collect(Collectors.toList());        // Terminal operation

        System.out.println(result); // Output: [ALICE, AMANDA]
    }
}