OneBite.Dev - Coding blog in a bite size

iterate over an array in java

Code snippet on how to iterate over an array in java

for (String element : array) {
  System.out.println(element);
}

This code iterates through an array of type String. The for loop first declares a variable called “element” which will represent each element in the array. Then, it states that the loop should repeat for each element in the array. Finally, it prints out the value of “element” using the print command. In other words, this code will print out each value in the array one by one.

java