☕ Java Intermediate

What is the Stream API in Java 8?

Why Interviewers Ask This

This question targets practical, hands-on experience with Java. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

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().

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Java answers easy to follow.