Array Type Streams QuizS2C Home « Array Type Streams Quiz

The questions in this quiz on Java are on the topics covered in the Streams section of the site. The table below lists the lesson used for each quiz, a description of the lesson content and the quiz number and questions associated with that lesson.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that quiz.

Click on a quiz in the table to go straight to the quiz for a particular lesson.

Generics Lessons Description Quiz Info.
Lesson 1 - Introducing StreamsIn our first lesson on on Streams we test your knowledge of the topics covered in the Introducing Streams lesson.Quiz1
9 questions
Lesson 2 - Stream PipelinesIn this lesson on streams we look at stream pipelines and how they work.Quiz2
9 questions
Lesson 3 - Stream Operations OverviewIn this lesson on streams we present an overview of the intermediate and terminal operations available.Quiz3
9 questions
Lesson 4 - Array Type StreamsIn this streams lesson we look at the various ways of creating streams from arrays.This quiz.
8 questions
Lesson 5 - Numeric StreamsIn this lesson on streams we look at numeric streams and the operations associated with them.Quiz5
7 questions
Lesson 6 - Other Stream CreationIn this lesson we take a final look at stream creation by creating streams from files, functions and iterations and also find out about creating infinite streams.Quiz6
9 questions
Lesson 7 - Finding & MatchingIn this streams lesson we look at the various ways of finding and matching values within our streams.Quiz7
9 questions
Lesson 8 - Reduction OperationsIn this streams lesson we look at reduction operations and how to use them.Quiz8
7 questions
Lesson 9 - Stream CollectorsIn this lesson we take a high level look at stream collectors by investigating the Collector<T,A,R> interface and the Collectors class implementation of it.Quiz9
8 questions
Lesson 10 - Collecting & Aggregating StreamsIn this lesson we look at how to create collections and aggregations from our streams.Quiz9
8 questions
Lesson 11 - Grouping & Partitioning StreamsThis lesson on streams is all about grouping & partitioning our streams.Quiz11
9 questions
Lesson 12 - Parallel StreamsThis lesson is all about parallel streams.Quiz12
8 questions

Streams Quiz 4

The quiz below tests your knowledge of the material learnt in Streams - Lesson 4 - Array Type Streams.

Question 1 : The Stream.of() and Arrays.stream() methods return the same type for object type arrays?
- The <code>Stream.of()</code> and <code>Arrays.stream()</code> method DO return the same type for object type arrays.
Question 2 : What would be printed from the following code snippet?
String[] strArray = {"one", "two", "three", "four"};
Stream<String> strArrayStream = Stream.of(strArray);
System.out.println(strArrayStream.count());
- The code snippet would print 4.
Question 3 : For primitive type arrays Stream.of() calls Arrays.stream() under the bonnet?
- For primitive type arrays <code>Stream.of()</code> DOES NOT call <code>Arrays.stream()</code> under the bonnet, it only does this for object type arrays.
Question 4 : The Arrays.stream() method can deal with any primitive type?
- The <code>Arrays.stream()</code> CAN deal with any primitive by using <code>DoubleStream</code> for float primitives and <code>IntStream</code> for anything else.
Question 5 : What would be printed from the following code snippet?
Stream strArrayStream2 = Stream.of(strArray);
strArrayStream2.forEach(System.out::print);
strArrayStream2.map(String::toUpperCase)
.forEach(System.out::print);
- The code snippet will compile ok but fails with the runtime error <code>IllegalStateException</code> as the stream has already been operated upon.
Question 6 : The Stream.of() and Arrays.stream() methods return the same type for primitive type arrays?
- The <code>Stream.of()</code> and <code>Arrays.stream()</code> method DO NOT return the same type for primitive type arrays. <code>Stream.of()</code> will return a stream with a single object and <code>Arrays.stream()</code> will return either a <code>DoubleStream()</code>, <code>IntStream()</code> or <code>LongStream()</code>.
Question 7 : Which streaming method is preferred when using primitive type arrays?
- If you're streaming primitives use the <code>Arrays.stream()</code> variants that were built for this purpose.
Question 8 : For object type arrays Stream.of() calls Arrays.stream() under the bonnet?
- For object type arrays <code>Stream.of()</code> DOES call <code>Arrays.stream()</code> under the bonnet.
Quiz Progress Bar Please select an answer

What's Next?

In the next quiz we test your knowledge of numeric streams.