How to Use For-each Loop in Java


In this example we will show you how to use for-each loop in Java.

Source Code

package com.beginner.examples;

public class ForEachLoop {
  public static void main(String[] args) {
    String[] strs = {"a", "b", "c", "d"};
    for (String str : strs) { // for-each loop
      System.out.println(str);
    }
  }
}

Output:

a
b
c
d
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments