Java Streams MCQs with answers Page - 5

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. What happens if `stream()` is called on a null List?

  • (A) Empty stream is returned
  • (B) NullPointerException is thrown
  • (C) Compilation error
  • (D) All elements are removed

A

Admin • 831.35K Points
Coach

Q. Which method would you use to get the maximum value from a Stream?

  • (A) max()
  • (B) maximum()
  • (C) findMax()
  • (D) collectMax()

A

Admin • 831.35K Points
Coach

Q. What is returned by `reduce()` when no identity is provided and the stream is empty?

  • (A) 0
  • (B) null
  • (C) Optional.empty()
  • (D) IllegalStateException

A

Admin • 831.35K Points
Coach

Q. Which of the following is not a valid intermediate operation?

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

A

Admin • 831.35K Points
Coach

Q. Which method returns true if the stream contains no elements?

  • (A) isEmpty()
  • (B) noneMatch(x -> true)
  • (C) count() == 0
  • (D) Both b and c

A

Admin • 831.35K Points
Coach

Q. Which method is used to create a Stream of primitive ints?

  • (A) IntStream.of()
  • (B) Stream.ofInt()
  • (C) IntStream.stream()
  • (D) Stream.of(int[])

A

Admin • 831.35K Points
Coach

Q. Which of the following types is a primitive specialization of Stream?

  • (A) DoubleList
  • (B) LongList
  • (C) IntStream
  • (D) StringStream

A

Admin • 831.35K Points
Coach

Q. What does `flatMapToInt()` return?

  • (A) Stream<Integer>
  • (B) IntStream
  • (C) DoubleStream
  • (D) LongStream

A

Admin • 831.35K Points
Coach

Q. What is the difference between `map()` and `flatMap()`?

  • (A) map flattens, flatMap transforms
  • (B) map transforms, flatMap flattens nested streams
  • (C) Both do the same
  • (D) flatMap does not exist

A

Admin • 831.35K Points
Coach

Q. Which collector is used to partition a stream into two groups?

  • (A) Collectors.toMap()
  • (B) Collectors.groupingBy()
  • (C) Collectors.partitioningBy()
  • (D) Collectors.dividingBy()
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