How to Loop Through an Array with For-each in Java


In this example we will show the method to loop through an array with for-each in Java.

Source Code

package com.beginner.examples;

public class LoopArray {
  public static void main(String[] args) {
    String[] strs = {"a", "b", "c"};
    for (String s : strs) { // loop through an array
      System.out.println(s);
    }
  }
}

Output:

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