☕ 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().
More Java Questions
View all →- Intermediate What is the Java Collections Framework?
- Intermediate What is the difference between ArrayList and LinkedList?
- Intermediate What is HashMap in Java and how does it work internally?
- Intermediate What is the difference between HashMap and HashTable in Java?
- Intermediate What is the difference between HashMap and LinkedHashMap?