Question 15
Back to Exercise
Which is the most efficient way to iterate over both keys and values?
- A for (K k : map.keySet()) map.get(k)
- B for (Map.Entry<K, V> e : map.entrySet()) Correct
- C for (V v : map.values())
- D for (int i = 0; i < map.size(); i++)
Correct Answer: Option B
keySet + get does an extra lookup per key.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!