9 - 2D Arrays
Imagine putting a bunch of bags or pencil cases into a box...
Those bags are arrays and the box is an array holding those bags!
What are we learning?
In this lesson we will:
Discuss some definitions
Verify that we are comfortable with 1-dimensional arrays
Discuss and practice working with 2D arrays
Table of Contents
Primitive vs. Abstract Data
Simple variables that can be stored in a single block of memory are called primitives. The typical primitive data types in a programming language are:
boolean
integer (byte, short, int, long, char)
float (float, double)
characters (char) - which are actually integers
On the other hand, abstract data types require more processing power and memory. They are a combination of the primitive types.
Examples:
2D Arrays ๐ข
What if you had a garbage bag full of pencil cases?
Think of a single array like a shelf holding jars.
Now think of a bookshelf with many numbered shelves, each holding jars.ย
Need the third jar on the top shelf? myShelf[0][2]
How about the second jar on the middle shelf? myShelf[2][1]
Need the entire middle shelf as an array? myShelf[2]
๐คย When is this useful?
All the time!ย Think about games like Tetris, Pacman, or Block Blast.
1-Dimensional (1D) Array โฌ๏ธ
2-Dimensional (2D) Array โฌ๏ธ