Java OCA OCP Practice Question 2810

Question

Which of the following prints out all of the values in props?

A.   props.keys().stream().map(k -> k .forEach(System.out::println); 

B.   props.keys().stream().map(k -> props.get(k))  
     .forEach(System.out::println); 

C.   props.keySet().stream().map(k -> k) .forEach(System.out::println); 

D.   props.keySet().stream().map(k -> props.get(k))  
     .forEach(System.out::println); 

E.   props.stream().map(k -> k) .forEach(System.out::println); 

F.   props.stream().map(k -> props.get(k)) .forEach(System.out::println); 


D.

Note

Options E and F do not compile because you can't get a stream directly from a Properties object.

Options A and B do not compile because the method is keySet(), not keys().

Option C outputs all of the keys, and Option D outputs all of the values.




PreviousNext

Related