CS Awesome - Unit 8 Vocabulary

studied byStudied by 14 people
0.0(0)
get a hint
hint

2d Array

1 / 8

Tags and Description

2D Arrays

9 Terms

1

2d Array

An array that holds items in a two dimensional grid. You can think of it as storing items in rows and columns (like a bingo card or battleship game). You can access an item (element) at a given row and column index.

New cards
2

2d Array Declaration

To declare an array, specify the type of elements that will be stored in the array, then ([][]) to show that it is a 2d array of that type, then at least one space, and then a name for the array. Examples: int[][] seats; String[][] seatingChart;

New cards
3

2d Array Creation

To create a 2d array, type the name and an equals sign then use the new keyword, followed by a space, then the type, and then [numRows][numCols]. Example: seatingChart = new String[5][4];. This will have 5 rows and 4 columns.

New cards
4

2d Array Index

You can access and set values in a 2d array using the row and column index. The first element in an array called arr is at row 0 and column 0 arr[0][0].

New cards
5

2d Array Initialization

You can also initialize (set) the values in the array when you first create it. In this case you don't need to specify the size of the array, it will be determined from the number of values that you specify. Example: String[][] seatingInfo = { {"Jamal", "Maria"}, {"Jake", "Suzy"}, {"Emma", "Luke"}}; This will create a 2d array with 3 rows and 2 columns.

New cards
6

2d Array Number of Rows

The number of rows (or height) is the length of the outer array. For an array arr use arr.length to get the number of rows in the array.

New cards
7

2d Array Number of Columns

The number of columns (or width) is the length of the inner array. For an array arr use arr[0].length to get the number of columns.

New cards
8

nested for loop

A for loop inside of another for loop. These are used to loop through all the elements in a 2d array. One loop can work through the rows and the other the columns.

New cards
9

out of bounds error

This happens when a loop goes beyond the last valid index in an array. Remember that the last valid row index is arr.length - 1. The last valid column index is arr[0].length - 1.

New cards

Explore top notes

note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 5 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 14 people
Updated ... ago
4.5 Stars(2)
note Note
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 27 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 10097 people
Updated ... ago
4.7 Stars(91)
note Note
studied byStudied by 47 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard39 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard100 terms
studied byStudied by 19 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard75 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard41 terms
studied byStudied by 51 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard91 terms
studied byStudied by 3 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard127 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard51 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard52 terms
studied byStudied by 171 people
Updated ... ago
5.0 Stars(1)