zuai-logo

2D Array

Sophie Anderson

Sophie Anderson

7 min read

Listen to this study note

Study Guide Overview

This unit covers 2D arrays, focusing on their use for organizing data in a grid-like structure. Key concepts include initializing 2D arrays, understanding their representation as both nested arrays and grids/tables, traversing 2D arrays using nested loops, and implementing algorithms with them. The unit also emphasizes avoiding ArrayIndexOutOfBoundsException and introduces double-index notation for accessing array elements.

The Big Takeaway From this Unit

2D Arrays: 2D Arrays can be used to organize data into a grid, and with the appropriate methods, we can access and manipulate this data.

Unit Overview

Exam Weighting

  • 7.5-10% of the test
  • Roughly 3 to 4 multiple-choice questions
  • Always FRQ #4, which tests your ability to make, traverse, and create algorithms with a 2D array.

Enduring Understanding

In the past two units, you've learned how to store data in an array or an ArrayList. Now it's time to take it to another dimension with 2D arrays. You can either think of them as a grid or as a nested array, and we'll use both methods of thinking in this unit. Using these, we'll learn how to set these up and also how to traverse them.

Building Computational Thinking

For this unit, we will first learn how to create and initialize 2D arrays with various types of objects. These will be nested arrays. When traversing a list, you need to use nested arrays for loops, and these will need to have proper bounds to avoid an ArrayIndexOutOfBoundsException. If you can master 2D arrays, you can easily do 3D and higher-dimensional arrays if you ever decide to continue using Java after this course!

Main Ideas for This Unit

  • Initializing 2D Arrays
  • Representations of 2D Arrays
  • Traversing 2D Arrays
  • 2D Array Algorithms

8.1: 2D Arrays

Initializing 2D Arrays

We can declare and initialize a 2D array in much the same form as a regular array, but with some subtle differ...

Question 1 of 11

🥳 Which of the following is the correct syntax to declare and initialize an empty 2D array of integers with 3 rows and 4 columns?

int[][] arr = new int[4][3];

int arr[][] = new int[3,4];

int[][] arr = new int[3][4];

int arr = new int[3][4];