Monday, 10 March 2025

Java 8 Stream API MCQ for Interview

 Question: Which of the following operations is a terminal operation in Java 8 Stream API?

Options:

A. map()
B. filter()
C. collect()
D. flatMap()
Answer:
C. collect()
Explanation:
The collect() method is a terminal operation in the Stream API, used to transform the elements of a stream into a collection, list, or another data structure. Terminal operations produce a result or a side-effect and close the stream.