Streams Quiz 5
The quiz below tests your knowledge of the material learnt in Streams - Lesson 5 - Numeric Streams.
Question 1 : Which method returns a stream consisting of unique values?
- The <code>distinct()</code> method returns a stream consisting of unique values.
Question 2 : There are purpose built streams for all primitive types?
- There are only purpose built streams for <code>double</code>, <code>int</code> and <code>long</code>.
Question 3 : Which method can be used to convert a primitive stream to an object stream?
- The <code>boxed()</code> method can be used to convert a primitive stream to an object stream.
Question 4 : The
reduce() method is an intermediate operator?
- The <code>reduce()</code> method is a terminal operator.
Question 5 : Which method produces a
- The <code>mapToDouble()</code> method produces a <code>DoubleStream</code> object.
Question 6 : Is the following code snippet valid where Employee.listOfStaff() returns List<Employee>?
double averageAge = Employee.listOfStaff().stream()
- There is no <code>sum()</code> method in the <code>Stream</code> interface, which is used for a list input, so the code is invalid.
Question 7 : Which simple construct can the
rangeClosed() method replace?
- The <code>rangeClosed()</code> method can replace the simple <code>for</code> construct.
Quiz Progress Bar Please select an answer
In the next quiz we test your knowledge of different types of stream creation.