About 870,000 results
Open links in new tab
  1. java - Iterate through 2 dimensional array - Stack Overflow

    Sep 12, 2014 · In the first block, the inner loop iterates over each item in the row before moving to the next column. In the second block (the one you want), the inner loop iterates over all the …

  2. How to use for loop with two dimensional array in Java

    Dec 29, 2019 · To loop over two dimensional array in Java you can use two for loops. Each loop uses an index. Index of outer for loop refers to the rows, and inner loop refers to the columns. …

  3. Java Multi-Dimensional Arrays - GeeksforGeeks

    Apr 23, 2025 · In Two dimensional array the the row is present by the i and the column is present by the j and we can get the element using arr [i] [j] using the nested loop. arr is the name of the …

  4. How to loop over two dimensional array in Java? Example - Blogger

    Aug 8, 2021 · How to loop over two dimensional array in Java? Example. You can loop over a two-dimensional array in Java by using two for loops, also known as nested loop. Similarly to …

  5. Java Multi-Dimensional Arrays - W3Schools

    Loop Through a Multi-Dimensional Array. You can also use a for loop inside another for loop to get the elements of a two-dimensional array (we still have to point to the two indexes):

  6. Iterating Through 2D Array Java - Coding Rooms

    Oct 5, 2020 · We explored using for loops with one-dimensional arrays. Now let’s jump into nested for loops as a method for iterating through 2D arrays. A nested for loop is one for loop …

  7. 9.2.4. Enhanced For-Each Loop for 2D Arrays — CS Java

    Since 2D arrays are really arrays of arrays you can also use a nested enhanced for-each loop to loop through all elements in an array. We loop through each of the inner arrays and loop …

  8. Arrays and Loops: Two-Dimensional Arrays Cheatsheet - Codecademy

    In Java, enhanced for loops can be used to traverse 2D arrays. Because enhanced for loops have no index variable, they are better used in situations where you only care about the values of …

  9. Java Multi-Dimensional Array and Enhanced for loop

    In Java, the enhanced for loop (for-each loop) can be used with multi-dimensional arrays to simplify the process of iterating over the elements. Here's an example illustrating how to use …

  10. Java Matrix - 2D Arrays - CodeGym

    Apr 6, 2025 · Here’s another way to print2D arrays in Java using “ foreach loop ”. This is a special type of loop provided by Java, where the int []row will loop through each row in the matrix. …