Java Streams MCQs with answers Page - 3

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 is used to convert a stream into an array?

  • (A) toArray()
  • (B) toList()
  • (C) toArrayList()
  • (D) collectArray()

A

Admin • 831.35K Points
Coach

Q. What is the result of calling `stream().distinct()`?

  • (A) All elements are sorted
  • (B) All duplicate elements are removed
  • (C) The stream is reversed
  • (D) All null values are removed

A

Admin • 831.35K Points
Coach

Q. Which of the following is a terminal operation?

  • (A) filter()
  • (B) map()
  • (C) collect()
  • (D) limit()

A

Admin • 831.35K Points
Coach

Q. Which method finds the minimum element of a Stream using a Comparator?

  • (A) least()
  • (B) smallest()
  • (C) min()
  • (D) findMin()

A

Admin • 831.35K Points
Coach

Q. Which of the following operations does NOT change the number of elements in a Stream?

  • (A) filter()
  • (B) flatMap()
  • (C) map()
  • (D) forEach()

A

Admin • 831.35K Points
Coach

Q. Which of these is an intermediate operation?

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

A

Admin • 831.35K Points
Coach

Q. What does `Collectors.joining()` do?

  • (A) Combines elements into a list
  • (B) Combines elements into a string
  • (C) Sorts elements
  • (D) Finds duplicates

A

Admin • 831.35K Points
Coach

Q. Which of these returns true if all elements match a given condition?

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

A

Admin • 831.35K Points
Coach

Q. What does `peek()` return?

  • (A) A list of elements
  • (B) The same stream after performing a side-effect
  • (C) A copy of the stream
  • (D) Null

A

Admin • 831.35K Points
Coach

Q. Can streams be reused once consumed?

  • (A) Yes, always
  • (B) Yes, if reset() is called
  • (C) No
  • (D) Only if the stream is infinite
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