Syntax

Java For-Each Loop Syntax

In Java, for-each loop: loops over every item in an array or collection — for (String item : items) { ... }

Quick Answer

Syntax
for (String item : items) { ... }
JavaSyntax

For-Each Loop

Code example
for (String item : items) { ... }

Loops over every item in an array or collection.

Learn More

How to for-each loop in Java

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

Java For-Each Loop Syntax

Use for (String item : items) { ... }.

Related Syntax References

Frequently asked questions

What is the Java syntax for for-each loop?

Use this pattern: for (String item : items) { ... }

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