Syntax

Java Loop over a Map Syntax

In Java, loop over a map: loops over keys and values — for (var e : ages.entrySet()) { e.getKey(); e.getValue(); }

Quick Answer

Syntax
for (var e : ages.entrySet()) { e.getKey(); e.getValue(); }
JavaSyntax

Loop over a Map

Code example
for (var e : ages.entrySet()) { e.getKey(); e.getValue(); }

Loops over keys and values.

Learn More

How to loop over a map in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java Loop over a Map Syntax

Use for (var e : ages.entrySet()) { e.getKey(); e.getValue(); }.

Related Syntax References

Frequently asked questions

What is the Java syntax for loop over a map?

Use this pattern: for (var e : ages.entrySet()) { e.getKey(); e.getValue(); }

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify