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 ยท Arrays Loop Through an Array Real-Life Examples Multidimensional Arrays Code Challenge
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ iterating-arrays-java
Java - Loop Through an Array - GeeksforGeeks
December 2, 2024 - // Java program to loop through ... int i, x; // Iterating over an array for (i = 0; i < a.length; i++) { // accessing each element of array x = a[i]; System.out.print(x + " "); } } } ... Example 2: The another method is using ...
๐ŸŒ
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.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ enhanced-for-loop
Java for-each Loop (With Examples)
// Calculate the sum of all elements ... int[] numbers = {3, 4, 5, -5, 0, 12}; int sum = 0; // iterating through each element of the array for (int number: numbers) { sum += number; } System.out.println("Sum = " + sum); } } ... As we can see, we have added each element of the numbers ...
๐ŸŒ
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
Here is our sample Java program to demonstrate how to loop through an array in Java. For simplicity, we have chosen an int array but you can use any type of array, both primitive and reference types. This technique will work for all kind of array, except the multi-dimensional array. In order to loop through the two-dimensional array, you need to use nested loops as shown in the example given here. Though there are several ways to iterate over an array, in this article, I'll show you two of the most common ways, first by using traditional for loop which uses the array index to move forward or backward and the second one using enhanced for loop of Java 5.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
CodingBat
codingbat.com โ€บ doc โ€บ java-array-loops.html
CodingBat Java Arrays and Loops
// (classic search-loop example) public int search(int[] nums, int target) { // Look at every element for (int i=0; i<nums.length; i++) { if (nums[i] == target) { return i; // return the index where the target is found } } // If we get here, the target was not in the array return -1; } For search problems, we generally write the loop in the standard way to go through all the elements, and then add if/break/return logic inside the loop to react to each element. As a matter of style, the search-loop solves two problems. It must iterate over all the elements, and it must figure out if the target is found or not.
๐ŸŒ
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
Just like in the last article, we learned about the best way to Iterate over each entry in HashMap, In this article, we will take a look at iteration over String array using both Java 1.5 enhanced for loop and traditional for loop. Here is the complete code example of How to iterate over the String array in Java.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-iterate-over-arrays-using-for-and-foreach-loop
Java Program to Iterate Over Arrays Using for and for-each Loop - GeeksforGeeks
July 23, 2025 - // Java program to iterate over an array // using for loop and for-each loop public class Loop { public static void main(String[] args) { int[] n = {1, 2, 3, 4, 5}; // Using for loop System.out.println("Using for loop:"); for (int i = 0; i < ...
๐ŸŒ
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; ...
๐ŸŒ
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
First trace through it on paper keeping track of the array and the index variable. Then, run it to see if you were right. You can also follow it in the visualizer by clicking on the Show Code Lens button. We can use iteration with a for loop to visit each element of an array.
๐ŸŒ
Quora
quora.com โ€บ Can-you-iterate-through-an-array-in-Java-using-only-one-loop
Can you iterate through an array in Java using only one loop? - Quora
Answer (1 of 2): Yes, you can iterate through an array in Java using only one loop. You can use a [code ]for[/code] loop to achieve this. [code]int[] numbers = {1, 2, 3, 4, 5}; for (int i = 0; i
๐ŸŒ
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 - Seven (7) ways to Iterate Through Loop in Java. * 1. Simple For loop * 2. Enhanced For loop * 3. Iterator * 4. ListIterator * 5. While loop * 6. Iterable.forEach() util * 7. Stream.forEach() util */ public class CrunchifyIterateThroughList { public static void main(String[] argv) { // create list List<String> crunchifyList = new ArrayList<String>(); // add 4 different values to list crunchifyList.add("Facebook"); crunchifyList.add("Paypal"); crunchifyList.add("Google"); crunchifyList.add("Yahoo"); // Other way to define list is - we will not use this list :) List<String> crunchifyListNew = Arrays.asList("Facebook", "Paypal", "Google", "Yahoo"); // Simple For loop System.out.println("==============> 1.
๐ŸŒ
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); } }
๐ŸŒ
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 ...