Java Streams MCQs with answers Page - 4

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 • 802.91K Points
Coach

Q. Which method checks if no elements in the stream match a predicate?

  • (A) anyMatch()
  • (B) noneMatch()
  • (C) noMatch()
  • (D) zeroMatch()

A

Admin • 802.91K Points
Coach

Q. Which Stream type is unordered by default?

  • (A) IntStream
  • (B) List.stream()
  • (C) Set.stream()
  • (D) Map.stream()

A

Admin • 802.91K Points
Coach

Q. Which method converts a primitive stream to a boxed stream?

  • (A) boxed()
  • (B) wrap()
  • (C) toBoxed()
  • (D) convert()

A

Admin • 802.91K Points
Coach

Q. How do you create an infinite stream?

  • (A) Stream.infinite()
  • (B) Stream.generate()
  • (C) Stream.loop()
  • (D) Stream.unbounded()

A

Admin • 802.91K Points
Coach

Q. Which method is used to execute stream operations in parallel?

  • (A) parallel()
  • (B) multiStream()
  • (C) split()
  • (D) asParallel()

A

Admin • 802.91K Points
Coach

Q. Which method converts a Stream into a Set?

  • (A) collect(Collectors.toSet())
  • (B) toSet()
  • (C) stream().set()
  • (D) set()

A

Admin • 802.91K Points
Coach

Q. Which method converts a List to a Stream?

  • (A) stream()
  • (B) toStream()
  • (C) listToStream()
  • (D) streamFromList()

A

Admin • 802.91K Points
Coach

Q. Which of the following Stream operations is most suitable for counting elements matching a condition?

  • (A) count()
  • (B) size()
  • (C) sum()
  • (D) collect()

A

Admin • 802.91K Points
Coach

Q. Which method returns the default value without inserting a new key?

  • (A) get()
  • (B) setdefault()
  • (C) pop()
  • (D) None of these

A

Admin • 802.91K Points
Coach

Q. What does the `findAny()` method return?

  • (A) First element of the stream
  • (B) Any element, possibly the first, wrapped in Optional
  • (C) All matching elements
  • (D) Null
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