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.