Loop through an array in Java


Following example shows how to loop through an array using a foreach loop.

public class Tester {
   public static void main(String[] args) {
      int[] dataArray = {1, 2, 3, 4};
      for(int i: dataArray) {
         System.out.println(i);
      }
   }
}

Updated on: 24-Feb-2020

174 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements