Java Streams MCQs with answers Page - 2

You will find multiple-choice questions (MCQs) related to #Java Streams here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 831.35K Points
Coach

Q. Which method checks if any element matches the given predicate?

  • (A) allMatch()
  • (B) findAny()
  • (C) anyMatch()
  • (D) noneMatch()

A

Admin • 831.35K Points
Coach

Q. Which method creates a stream from an array?

  • (A) Stream.ofArray()
  • (B) Arrays.stream()
  • (C) List.stream()
  • (D) ArrayList.stream()

A

Admin • 831.35K Points
Coach

Q. Which method returns an Optional describing the first element?

  • (A) first()
  • (B) findFirst()
  • (C) getFirst()
  • (D) peek()

A

Admin • 831.35K Points
Coach

Q. Which method skips the first n elements of the stream?

  • (A) skip()
  • (B) ignore()
  • (C) omit()
  • (D) pass()

A

Admin • 831.35K Points
Coach

Q. Which stream operation is lazy?

  • (A) forEach()
  • (B) collect()
  • (C) map()
  • (D) count()

A

Admin • 831.35K Points
Coach

Q. What is the output type of `Stream.map()`?

  • (A) List
  • (B) Stream
  • (C) Object[]
  • (D) Optional

A

Admin • 831.35K Points
Coach

Q. Which Stream method is used for debugging purposes by peeking at elements?

  • (A) watch()
  • (B) debug()
  • (C) peek()
  • (D) observe()

A

Admin • 831.35K Points
Coach

Q. What does `flatMap()` do in Java Streams?

  • (A) Flattens a stream of streams into a single stream
  • (B) Filters elements
  • (C) Sorts elements
  • (D) Creates nested lists

A

Admin • 831.35K Points
Coach

Q. Which of the following statements is true about Streams?

  • (A) Streams modify the original collection
  • (B) Streams support parallel execution
  • (C) Streams store data
  • (D) Streams are reusable

A

Admin • 831.35K Points
Coach

Q. Which method is used to obtain a sequential stream from a collection?

  • (A) stream()
  • (B) sequentialStream()
  • (C) createStream()
  • (D) newStream()
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More