Zachary Sweeney Zachary Sweeney - 1 year ago 63
Java Question

Using two for loops to loop through a 2D array in java

How do I use two for loops to loop through a 2D array?
for example-
1st for loop ---

for(int step = 0; step<array.length; step++){

2nd for loop ---

Jan Jan
Answer Source

As you have a 2-d array, you have two length values for each loop:

  //you have this? array[][];
  for(int i = 0; i < array.length; ++i) {
    for(int j = 0; j < array[i].length; ++j) {
      //do something on array[i][j] 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download