How to Loop Through an Array in Java


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

Source Code

package com.beginner.examples;

public class LoopAnArray {
  public static void main(String[] args) {
    String[] strs = {"a", "b", "c"};
    for (int i = 0; i < strs.length; i++) { // loop through an array
      System.out.println(strs[i]);
    }
  }
}

Output:

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