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: 2020-02-24T10:19:29+05:30

266 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements