Java SE 8 Programmer II — Question 99
Given the code fragment:
List<String> nL = Arrays.asList("Jim", "John", "Jeff");
Function<String, String> funVal = s -> "Hello : ".concat(s); nL.Stream()
.map(funVal)
.forEach(s-> System.out.print (s));
What is the result?
Answer options
- A. Hello : Jim Hello : John Hello : Jeff
- B. Jim John Jeff
- C. The program prints nothing.
- D. A compilation error occurs.
Correct answer: C
Explanation
The code contains a syntax error due to the incorrect method call 'nL.Stream()' which should be 'nL.stream()' (with a lowercase 's'). Because of this, a compilation error occurs, making option C incorrect and showing that the program does not print anything.