J.IV · Java 25 practice question

A developer is deciding whether to expose a Collection or a Stream from a repository method. According to the Java SE 25 API, what is the primary difference in their goals?

Choose one answer
Check answer and explanation

Correct answer: Collections focus on managing and accessing elements, whereas streams declaratively describe a source and aggregate operations on it.

Explanation

Collections are designed for efficient management of and access to elements, while streams declaratively describe their source and the aggregate computations performed on it without providing direct element manipulation.

Common trap

Many developers associate streams with parallelism, but streams support both sequential and parallel operations rather than being exclusively parallel. Standard collections such as ArrayList are mutable by default, and streams explicitly do not provide direct element manipulation.

Source: Java SE 25 API: Stream
Checked against the cited text on 2026-11-25.

Report an error in this question