What statements about the following code are true? (Choose all that apply.)
import java.util.Arrays; public class Main { public static void main(String[] args) { System.out.println(Arrays.asList("abc","Java","Javascript","SQL") .parallelStream().parallel() // q1 .reduce(0, // w ww.jav a2s . c o m (c1, c2) -> c1.length() + c2.length(), // q2 (s1, s2) -> s1 + s2)); // q3 } }
C.
The code does not compile, so A and E are incorrect.
The problem here is that c1 is a String but c2 is an int, so the code fails to combine on line q2, since calling length()
on an int is not allowed, and C is correct.
The rest of the lines compile without issue.
Note that calling parallel()
on an already parallel is allowed, and it may in fact return the same object.