What does the following output?
import java.util.*; public class Main { public static void main(String[] args) { Map<Integer, Integer> map = new HashMap<>(); map.put(9, 3);/*from w w w.j a va 2s.c om*/ Map<Integer, Integer> result = map.stream().map((k,v) -> (v,k)); System.out.println(result.keySet().iterator().next()); } }
C.
As tempting as it is, you can't actually convert a Map into a Stream directly, which means you can't call the map()
method on it either.
You can build a Stream out of the keys or values or key/value pairs.
Since this code doesn't compile, Option C is correct.