You can do an enhanced for loop (for java 5 and higher) for iteration on array's elements:

String[] elements = {"a", "a", "a", "a"};   
for (String s: elements) {           
    //Do your stuff here
    System.out.println(s); 
}
Answer from Michal on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_arrays_loop.asp
Java Loop Through an Array
For Loop Nested Loops For-Each Loop Real-Life Examples Code Challenge Java Break/Continue Java Arrays
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ enhanced-for-loop
Java for-each Loop (With Examples)
class Main { public static void main(String[] args) { char[] vowels = {'a', 'e', 'i', 'o', 'u'}; // iterating through an array using the for-each loop for (char item: vowels) { System.out.println(item); } } } ... Here, the output of both programs is the same.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ iterating-arrays-java
Java - Loop Through an Array - GeeksforGeeks
December 2, 2024 - // Java Program to iterate over ... for loop import java.io.*; public class GFG { public static void main(String[] args) { // Array Created int a[] = { 1, 2, 3, 4, 5 }; // Iterating using for-each or // enhanced for loop for (int i : a) System.out.print(i + " "); } } ... Example ...
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 02 โ€บ how-to-loop-through-array-in-java-with.html
How to loop through an Array in Java? Example Tutorial
The traditional loop uses a counter and allows you to iterate until the last element is reached i.e. counter is equal to the length of the array while enhanced for loop maintains that counter internally, allowing you to iterate without worrying about counts. This results in clean code and also eliminates the possibility of one-off errors. In this article, I'll show you 2 ways to iterate over an array, first by using traditional for loop and second by using enhanced for loop of Java 1.5.
๐ŸŒ
CodingBat
codingbat.com โ€บ doc โ€บ java-array-loops.html
CodingBat Java Arrays and Loops
In contrast, Java Lists can grow and shrink over time -- this is a big feature that Lists have that arrays do not. The length of an array can be accessed as a special ".length" attribute. For example, with the above "values" array, we can access the size of the array as "values.length". It is common to use a 0...length-1 for-loop to iterate over all the elements in array:
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-and-array-iteration-what-beginners-need-to-know-22a44dd32afb
Java and Array Iteration โ€” What Beginners Need to Know
June 17, 2024 - In this example, the loop starts with the index i initialized to 0. The condition i < numbers.length && numbers[i] != target makes sure that the loop continues as long as i is less than the length of the array and the current element is not equal to the target. The index i is incremented by 1 in each iteration until the target is found or the end of the array is reached. Beyond the basic iteration methods, Java offers more advanced techniques to iterate over arrays.
Find elsewhere
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ java tutorials โ€บ for-each loop in java
For-each loop in Java
November 8, 2024 - This is the conventional approach of the โ€œforโ€ loop: for(int i = 0; i< arrData.length; i++){ System.out.println(arrData[i]); } You can see the use of the counter and then use it as the index for the array.
๐ŸŒ
Java67
java67.com โ€บ 2013 โ€บ 08 โ€บ how-to-iterate-over-array-in-java-15.html
How to iterate over an Array in Java using foreach loop Example Tutorial | Java67
Java 1.5 foreach loop provides an elegant way to iterate over array in Java. In this programming tutorial, we will learn how to loop over String array in Java by using foreach loop.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ for-each-loop-in-java
For-Each Loop in Java - GeeksforGeeks
1 month ago - Example 2: Iterating in a List using for-each loop ... import java.util.*; class Geeks { public static void main(String[] args) { List<Integer> list = new ArrayList<>(); list.add(3); list.add(5); list.add(7); list.add(9); int max = Integer.MIN_VALUE; for (int num : list) { if (num > max) { max = num; } } System.out.println("List of Integers: " + list); System.out.println("Maximum element: " + max); } }
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ csjava โ€บ Unit7-Arrays โ€บ topic-7-2-traversing-arrays.html
7.2. Traversing Arrays with For Loops โ€” CS Java
Just start the index at 0 and loop while the index is less than the length of the array. Note that the variable i (short for index) is often used in loops as the loop counter variable and is used here to access each element of an array with its index. ... For example, here is a loop traversing the highScores array to print every score...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ what-are-the-different-ways-to-iterate-over-an-array-in-java
What are the different ways to iterate over an array in Java?
July 2, 2020 - import java.util.Arrays; public class IteratingArray { public static void main(String args[]) { //Creating an array int myArray[] = new int[7]; //Populating the array myArray[0] = 1254; myArray[1] = 1458; myArray[2] = 5687; myArray[3] = 1457; myArray[4] = 4554; myArray[5] = 5445; myArray[6] = 7524; ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ iterating-arraylists-java
Iterating over ArrayLists in Java - GeeksforGeeks
Now it is a further additive to the article as we are done with discussing all methods that can be used to iterate over elements. Till now we have traversed over input elements only and have not seen the traversal what if we play with elements, so do we are considering ยท Example ยท Java ยท import java.util.List; import java.util.ArrayList; import java.util.Iterator; public class GFG { public static void main(String[] args) { // Creating a List with referenceto ArrayList List<Integer> al = new ArrayList<Integer>(); al.add(10); al.add(20); al.add(30); al.add(1); al.add(2); // Remove elements smaller than 10 using // Iterator.remove() Iterator itr = al.iterator(); while (itr.hasNext()) { int x = (Integer)itr.next(); if (x < 10) itr.remove(); } System.out.println("Modified ArrayList : " + al); } } Output ยท
Published ย  January 19, 2026
Top answer
1 of 5
3

The better question might be: Why wouldn't you want to use a FOR loop to iterate through an array? There are many ways to iterate through an Array or a collection and there is no law that states you have to use the FOR loop. In a lot of cases, it's simply the best to use for speed, ease of use, and readability. And yet, in other cases it is not:

The Array:

int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

Display Array with the typical for loop:

for (int i = 0; i < array.length; i++) {
    System.out.println(array[i]);
}

Display Array with the enhanced for loop:

for(Integer num : array) {
    System.out.println(num);
}

Display Array with the do/while loop:

int i = 0;
do {
    System.out.println(array[i++]);
} while (i < array.length);

Display Array with the while loop:

int j = 0;
while (j < array.length) {
    System.out.println(array[j++]);
}

Display Array through Recursive Iteration:

iterateArray(array, 0);  // 0 is the start index.


// The 'iterateArray()' method:
private static int iterateArray(int[] array, int index) {
    System.out.println(array[index]);
    index++; 
    if (index == array.length) {
        return 0;
    }
    return iterateArray(array,index);
}

Display Array using Arrays.stream() (Java8+):

Arrays.stream(array).forEach(e->System.out.print(e + System.lineSeparator())); 

Display Array using IntStream (Java8+):

IntStream.range(0, array.length).mapToObj(index -> array[index]).forEach(System.out::println);

Choose your desired weapon....

2 of 5
1
Considering you have an array like : 
int[] array = {1,2,4,5,6};

You can use stream to iterate over it, apart from printing you can perform lot many thing over this array.

Arrays.stream(array).forEach(System.out::println);

Similarly you can do lot many action over collections as well:

List<String> myList = new ArrayList<>(); List
myList.add("A");
myList.add("B");
    

Stream.of(myList).forEach(System.out::println);

myList.forEach(System.out::println);

๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ iterate-over-arraylist
Java Program to Iterate over an ArrayList
Here, we have used the for-each ... main(String[] args) { // Creating an ArrayList ArrayList<Integer> numbers = new ArrayList<>(); numbers.add(1); numbers.add(3); numbers.add(2); System.out.println("ArrayList: " + numbers); // Creating an instance of ListIterator ...
๐ŸŒ
Quora
quora.com โ€บ What-is-iteration-What-does-it-mean-to-iterate-through-an-array-in-Java
What is iteration? What does it mean to iterate through an array in Java? - Quora
Often, this is just done using a for loop: public static void main(String args[]) throws IOException ... int i, x; //declare an integer for loop counting. Declare an integer to hold the value accessed in the Array.
๐ŸŒ
Crunchify
crunchify.com โ€บ java j2ee tutorials โ€บ how to iterate through java list? seven (7) ways to iterate through loop in java
How to iterate through Java List? Seven (7) ways to Iterate Through Loop in Java โ€ข Crunchify
December 28, 2025 - How to iterate through Java List? This tutorial demonstrates the use of ArrayList, Iterator and a List. There are 7 ways you can iterate through List.