Skip to content
CodeKruPro

Valid ways to loop over a map

QuizEasy-MediumJava onlyAsked in: Accenture, Infosys, TCS

Map<String, Integer> stock. Which loops compile and visit every key with its value? Pick all that apply.

  • for (Map.Entry<String, Integer> e : stock.entrySet()) { ... e.getKey() ... e.getValue() ... }
  • stock.forEach((k, v) -> System.out.println(k + "=" + v));
  • for (String k : stock.keySet()) { ... stock.get(k) ... }
  • for (Map.Entry<String, Integer> e : stock) { ... }

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in