OneBite.Dev - Coding blog in a bite size

loop array in java

Code snippet on how to loop array in java

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

This code is used to loop through an array in Java. It starts by declaring a variable ‘i’ and setting it equal to zero. Then, it checks whether ‘i’ is smaller than the length of the array. If it is, the code will perform the actions within the loop. Finally, the variable ‘i’ is incremented by one each time the loop runs until it is no longer less than the length of the array. In this example, the code within the loop prints each item in the array.

java