0% found this document useful (0 votes)
26 views

Two Arrays Java

The document defines a 2D array in Java called A with 6 rows and 5 columns. It then explains that a 2D array in Java is actually an array of arrays, with the outer array containing references to the inner arrays. So A is a 1D array of references, with each element referencing a 1D integer array of length 5. This allows 2D array access using two indices, like A[row][column].

Uploaded by

Athanasios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Two Arrays Java

The document defines a 2D array in Java called A with 6 rows and 5 columns. It then explains that a 2D array in Java is actually an array of arrays, with the outer array containing references to the inner arrays. So A is a 1D array of references, with each element referencing a 1D integer array of length 5. This allows 2D array access using two indices, like A[row][column].

Uploaded by

Athanasios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

int [][] A = new int[6][5];

A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]

A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]

A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]

A[3][0] A[3][1] A[3][2] A[3][3] A[3][4]

A[4][0] A[4][1] A[4][2] A[4][3] A[4][4]

A[5][0] A[5][1] A[5][2] A[5][3] A[5][4]

This is how java understands 2D arrays.

A[0]

A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]

A[1]

A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]

A[2]

A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]

A[3]

A[3][0] A[3][1] A[3][2] A[3][3] A[3][4]

A[4]

A[4][0] A[4][1] A[4][2] A[4][3] A[4][4]

A[5]

A[5][0] A[5][1] A[5][2] A[5][3] A[5][4]

A is a reference to a 1 dimensional array of references.


Every element in the one-dimensional array of reference is a reference to an 1 dimensional array of
integers.

A[0]

A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]

A[1]

A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]

A[2]

A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]

A[3]

A[3][0] A[3][1] A[3][2] A[3][3] A[3][4]

A[4]

A[4][0] A[4][1] A[4][2] A[4][3] A[4][4]

A[5]

A[5][0] A[5][1] A[5][2] A[5][3] A[5][4]

You might also like