Stream API

1.Which of the following is NOT a characteristic of Java Streams?
  • A. They are designed for bulk operations on collections.
  • B. They are immutable; operations produce new streams.
  • C. They are terminal operations are eager.
  • D. They are meant for modifying the underlying data source.

They are meant for modifying the underlying data source.

They are meant for modifying the underlying data source.

2.Which method is used to create a stream from a Collection?
  • A. createStream()
  • B. toStream()
  • C. stream()
  • D. generateStream()

stream()

stream()

3.Which of the following is a terminal operation in the Stream API?
  • A. map()
  • B. filter()
  • C. forEach()
  • D. sorted()

forEach()

forEach()

4.What is the purpose of the Collectors.toList() method in the Stream API?
  • A. To filter elements based on a predicate.
  • B. To transform elements into a new type.
  • C. To collect elements from a stream into a List.
  • D. To sort the elements in a stream.

To collect elements from a stream into a List.

To collect elements from a stream into a List.

5.What does the intermediate operation do in a Stream pipeline?
  • A. It immediately processes the elements and produces a result.
  • B. It returns a new stream, allowing for chaining of operations.
  • C. It modifies the original data source.
  • D. It signals the end of the stream processing.

It returns a new stream, allowing for chaining of operations.

It returns a new stream, allowing for chaining of operations.