Finding & Matching QuizJ8 Home « Finding & Matching Quiz

Streams Quiz 7

The quiz below tests your knowledge of the material learnt in Streams - Lesson 7 - Finding & Matching.

Question 1 : Which of these methods returns null when the stream is empty?
- The <code>findAny()</code> and <code>findNone()</code> methods both return an <code>Optional</code>Optional object not a <code>null</code>.
Question 2 : Using the findFirst() method on a stream created from a list does not guarantees that the first element found will be the first in order?
- Using the <code>findFirst()</code> method on a stream created from a list DOES guarantee that the first element found will be the first in order as streams respect ordering.
Question 3 : What would be printed from the following code snippet if no employess were over 71?
Optional age = Employee.listOfStaff().stream()
.filter(e -> e.getAge() > 71)
.findFirst();
System.out.println(age);
- There are no finds for the <code>findFirst()</code> method so the code snippet would print <code>Optional.empty</code>.
Question 4 : The matching terminal operators return an Optional?
- The matching terminal operators return a <code>boolean</code> not an <code>Optional</code>.
Question 5 : Which of these methods returns a boolean?
- The <code>anyMatch()</code> method returns a <code>boolean</code>.
Question 6 : The finding terminal operators return an Optional?
- The finding terminal operators DO return an <code>Optional</code>.
Question 7 : What would be printed from the following code snippet if no employess were over 70?
System.out.println(Employee.listOfStaff().stream()
.anyMatch(e -> e.getAge() > 70));
- There are no matches for the <code>anyMatch()</code> method so the code snippet would print <code>false</code>.
Question 8 : The matching terminal operators return a boolean?
- The matching terminal operators DO return a <code>boolean</code>.
Question 9 : What would be printed from the following code snippet if no employess were over 70?
System.out.println(Employee.listOfStaff().stream()
.noneMatch(e -> e.getAge() > 70));
- There are no matches for the <code>noneMatch()</code> method so the code snippet would print <code>true</code>.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge of stream reduction operations.