2D Arrays

studied byStudied by 103 people
3.0(1)
get a hint
hint

2D Arrays

1 / 9

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

10 Terms

1

2D Arrays

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

New cards
2

Array of Arrays

A 2D array

New cards
3

Rows length

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

New cards
4

Columns length

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

New cards
5

Indexes

Positions in a 2D array

New cards
6

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

New cards
7

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.

New cards
8

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]);
New cards
9

What index does any array start at?

0

New cards
10

What index does an array end at?

array.length - 1

New cards

Explore top notes

note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 26 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 18 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 85 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 3979 people
Updated ... ago
5.0 Stars(27)

Explore top flashcards

flashcards Flashcard124 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard34 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard28 terms
studied byStudied by 38 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard26 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard40 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard22 terms
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard87 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard26 terms
studied byStudied by 3480 people
Updated ... ago
4.1 Stars(42)