2D Arrays

3.5(2)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

2D Arrays

Arrays that have rows and columns, forming a grid-like structure.

2
New cards

Array of Arrays

A 2D array

3
New cards

Rows length

The number of rows in a 2D array, accessed using arrayName.length.

4
New cards

Columns length

The length of the first column in a 2D array, accessed using arrayName[0].length.

5
New cards

Indexes

Positions in a 2D array

6
New cards

Initialize a 2D array by elements

int[][] numbers = {{1,2,3,4},{5,6,7,8}};

This would create the two-dimensional array with first row as array [1, 2, 3, 4] and second row as array [5, 6, 7, 8].

7
New cards

Initialize a 2D array by size

int[][] numbers = new int[2][2];
numbers[0][0] = 0;
//...

This would create the two dimensional array with 2 rows and 2 columns. Then you can set the values of individual elements using the row and column index.

8
New cards

How do you access an element of a 2D array?

Use the row index (r), then the column index (c), as shown.

Example: Access element in second row, first column. This would print “5”.

int[][] numbers = {{1,2,3,4},{5,6,7,8}};
System.out.print(numbers[1][0]);
9
New cards

What index does any array start at?

0

10
New cards

What index does an array end at?

array.length - 1