About 1,470,000 results
Open links in new tab
  1. Foreach with multidimensional arrays in Java - Stack Overflow

    Feb 25, 2015 · Imagine your multi-dimensional array as (x, y, z). When you iterate over first coordinate, you fix x (x = 1, 2, ..., n) and get (y, z) 2d-array. Then you fix y(y = 1, 2, ..., m) and …

  2. Java Multi-Dimensional Arrays - GeeksforGeeks

    Apr 23, 2025 · The for-each loop in Java (also called the enhanced for loop) was introduced in Java 5 to simplify iteration over arrays and collections. It is cleaner and more readable than …

  3. 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):

  4. Iterate over Multidimensional Arrays with for-each in Java

    The following code shows how to iterate over Multidimensional Arrays with for-each. public static void main(String args[]) { int sum = 0; int nums[][] = new int[3][5]; // give nums some values. for …

  5. java - For each loop using 2D array - Stack Overflow

    Nov 14, 2012 · for(int[] u: uu) is simply a for-each iteration rows, with the same principle of for(int row = 0; row < container.length; row++), and u or respectively container[row] are not elements …

  6. How to iterate a Multidimensional Array? - GeeksforGeeks

    Nov 7, 2022 · Doing this for the whole multidimensional array will iterate over all elements of the multidimensional array. Example 1: Iterating over a 2-D array. Example 2: Iterating over a 3D …

  7. 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 …

  8. Java Array multidimensional Arrays for each loop iterate

    We can use the for-each loop on multidimensional arrays. Java multidimensional arrays is arrays of arrays. A two-dimensional Java array is an array of one-dimensional arrays. public static …

  9. java - Print multi-dimensional array using foreach - Stack Overflow

    Jun 7, 2016 · Your loop will print each of the sub-arrays, by printing their address. Given that inner array, use an inner loop: for(int[] arr2: array1) { for(int val: arr2) System.out.print(val); }

  10. Multidimensional Arrays | Java Tutorial - CodeWithHarry

    The simplest way of looping through an array is to use a simple for-each loop. Example: public class ArrayExample { public static void main ( String [] args ) { //creating array objects String [] …

Refresh