Other Stream Creation QuizJ8 Home « Other Stream Creation Quiz

Streams Quiz 6

The quiz below tests your knowledge of the material learnt in Streams - Lesson 6 - Other Stream Creation.

Question 1 : The generate() method produces values from a constant iteration over a function?
- The <code>generate()</code> method produces new values, its the <code>iterate()</code> method that produces values from a constant iteration over a function.
Question 2 : Which Files class static method returns a lazily populated Stream, the elements of which are the entries in the directory?
- The <code>list()</code> static method of the <code>Files</code> class returns a lazily populated <code>Stream</code>, the elements of which are the entries in the directory.
Question 3 : We can create infinite streams?
- We CAN create infinite streams using the <code>iterate()</code> and <code>generate()</code> methods.
Question 4 : If you were extracting lines from a file and you wanted just one stream rather than a stream for each line which method would you use to achieve this?
- If you were extracting lines from a file and you wanted just one stream rather than a stream for each line you would use the <code>flatMap()</code> method.
Question 5 : The count() method can be used to restrict infinite streams?
- The <code>count()</code> method is a terminal operator that just sums up the values of a stream. To restrict infinite streams we would use the <code>limit()</code> intermediate operator to limit the size of the stream.
Question 6 : Which of the following methods will process a function infinitely?
- The <code>iterate()</code> method will process a function infinitely.
Question 7 : The java.nio.file Api was specifically updated in Java8 to take advantage of streams
- The <code>java.nio.file</code> Api WAS specifically updated in Java8 to take advantage of streams.
Question 8 : Which of the following methods can produce an infinite stream?
- The <code>generate()</code> method CAN produce an infinite stream.
Question 9 : The iterate() method produces bounded streams?
- The <code>iterate()</code> method DOES NOT produce <i>bounded</i> streams because results are produced <i>on the fly</i>, so can be infinite or <i>unbounded</i>.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge of stream finding and matching operations.