☕ Java Intermediate

What is the Stream API in Java 8?

Answer

The Stream API provides a functional approach to processing collections of elements. A stream is a sequence of elements supporting sequential and parallel aggregate operations — it does not store data (unlike a collection). Operations are: intermediate (lazy, return another stream): filter, map, flatMap, sorted, distinct, limit; and terminal (eager, produce a result or side effect): collect, forEach, reduce, count, findFirst. Streams are consumed once. Example: list.stream().filter(s -> s.startsWith("A")).map(String::toUpperCase).collect(Collectors.toList()). For parallel processing, use parallelStream().