AP Computer Science A College Board
Full course content, a smart revision plan and instant past paper feedback for AP Computer Science A College Board.
Start revising this course →Content Overview
58 topics in 10 modules
☑️ 2D Array 2 topics
- 2D Arrays
- Traversing 2D Arrays
☑️ Array 4 topics
- Array Creation and Access
- Developing Algorithms Using Arrays
- Enhanced for Loop for Arrays
- Traversing Arrays
☑️ ArrayList 7 topics
- ArrayList Methods
- Developing Algorithms Using ArrayLists
- Ethical Issues Around Data Collection
- Introduction to ArrayList
- Searching
- Sorting
- Traversing ArrayLists
☑️ Boolean Expressions and if Statements 7 topics
- Boolean Expressions
- Comparing Objects
- Compound Boolean Expressions
- Equivalent Boolean Expressions
- else if Statements
- if - else Statements
- if Statements and Control Flow
☑️ Inheritance 7 topics
- Creating References Using Inheritance Hierarchies
- Creating Superclasses and Subclasses
- Object Superclass
- Overriding Methods
- Polymorphism
- Writing Constructors
- super Keyword
☑️ Iteration 5 topics
- Developing Algorithms Using Strings
- Informal Code Analysis
- Nested Iteration
- for Loops
- while Loops
☑️ Primitive Types 5 topics
- Casting and Ranges of Variables
- Compound Assignment Operators
- Expressions and Assignment Statements
- Variables and Data Types
- Why Programming? Why Java?
☑️ Recursion 2 topics
- Recursion
- Recursive Searching and Sorting
☑️ Using Objects 9 topics
- Calling a Non-void Method
- Calling a Void Method
- Calling a Void Method with Parameters
- Creating and Storing Objects (Instantiation)
- Objects: Instances of Classes
- String Methods
- String Objects: Concatenation, Literals, and More
- Using the Math Class
- Wrapper Classes: Integer and Double
☑️ Writing Classes 10 topics
- Accessor Methods
- Anatomy of a Class
- Constructors
- Documentation with Comments
- Ethical and Social Implications of Computing Systems
- Mutator Methods
- Scope and Access
- Static Variables and Methods
- Writing Methods
- this Keyword
AP Computer Science A Revision Content
Take a look at the written content available for this course. Practice-question availability may vary.
AP Computer Science A - 2D Array - 2D Arrays Content Preview
2D Array
2D Arrays
Understanding 2D Arrays
- An array is a data structure that stores a fixed-size sequential collection of elements of the same type.
- A 2D array, also known as a matrix, stores data in a grid format. It has rows and columns, similar to a table.
- In Java, a 2D array is an array of arrays. Each row of the 2D array is a 1D array.
- 2D arrays are useful for representing data structures such as spreadsheets, grids, and games boards.
Declaration and Initialization
- To declare a 2D array in Java, you use the syntax:
type[][] arrayName;
- Initialization can take place at declaration, using nested curly braces
{}
. For example:int[][] matrix = {{1,2,3},{4,5,6},{7,8,9}};
- The size of the array can be defined during initialization as
type arrayName[][] = new type[rows][cols];
Accessing Elements
- Elements of a 2D array can be accessed using their row index and column index. Remember, Java is zero-indexed, so indexing starts at 0.
- The syntax to access an element is:
arrayName[row][column]
- The value can be changed in a similar way:
arrayName[row][column] = newValue;
Traversing a 2D Array
- To traverse, or go through each element of a 2D array, we use nested loops. The outer loop iterates through the rows and the inner loop iterates through the columns.
- Sample syntax can be:
for(int i = 0; i < rows; i++){ for(int j = 0; j < cols; j++){ System.out.print(arrayName[i][j] + " "); } System.out.println(); }
2D Array Methods and Properties
- You can use the
.length
property to get the number of rows in the 2D array. Note that this does not give the total number of elements in the array. - To get the number of columns, or the size of a particular row, we use
arrayName[row].length
- Methods that can be used with arrays include
Arrays.toString()
andArrays.deepToString()
for printing,Arrays.sort()
for sorting, andArrays.equals()
to check if two arrays are equal.
Question: Write the Java code to create a 2D array titled "myArray" which has 3 rows and 4 columns, and then update the value at the 2nd row and 3rd column to 5.
Unlock instant, personalised feedback
Sign up to Adapt to practise the exam questions available for this course with instant, personalised feedback.
Start revising this course →Try Adapt now
Add this exact course and build your personalised revision plan.