Java: how to get individual int values ​​from int [] []

I have an int [] [] object. It is defined in my code as shown below:

public int[][] position = { {20, 30}, {73, 91}, {82, 38} }; 

Is it possible to get the value of the first value (on the left) in each of the pairs of parentheses and save them as separate int variables using a for loop? Basically, can I extract "20", "73" and "82" and store them in int variables separately?

+8
java int extract
source share
1 answer
 for(int[] x : position){ int y = x[0]; // Do something with y... } 

Or simply:

 int x = position[0][0]; int y = position[1][0]; int y = position[2][0]; 
+12
source share

All Articles