Java Array and ArrayList Cheat Sheet

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

flashcard set

Earn XP

Description and Tags

Flashcards for reviewing Java Arrays and ArrayLists, including 2D arrays, ArrayList algorithms, comparisons between Arrays and ArrayLists, and array algorithms.

Last updated 10:55 AM on 5/5/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

26 Terms

1
New cards

Java Array

A data structure that stores a fixed-size sequential collection of elements of the same type.

2
New cards

Java ArrayList

A dynamic array implementation in Java that can grow or shrink in size. Part of Java's Collection framework.

3
New cards

2D Arrays

Declaration: int[][] things = new int[3][6]; (3 rows, 6 columns)

4
New cards

Rows

The number of rows in a 2D array.

5
New cards

Columns

The number of columns in a specific row (e.g., row 0) of a 2D array.

6
New cards

Accessing elements (valid)

Examples: things[0][0], things[0][3], things[1][0] to things[1][5], things[2][1] to things[2][4]

7
New cards

Accessing elements (invalid)

Examples: things[8][1], things[2][9], things[@][2], things[8][53]

8
New cards

Traversing 2D Arrays

Nested for-loop: for (int i = 0; i < things.length; i++) { for (int j = 0; j < things[0].length; j++) { System.out.println(things[i][j]); } }

9
New cards

Rule for Traversing 2D Arrays

Rows = outer loop, Columns = inner loop

10
New cards

ArrayList Algorithms - Remove Items

Backward loop: for (int i = cars.size() - 1; i >= 0; i--) { if (cars.get(i).getColor().equals("red")) { cars.remove(i); } }

11
New cards

ArrayList Algorithms - Find Index of Item

For loop: for (int i = 0; i < cars.size(); i++) { if (cars.get(i).getColor().equals("red")) return i; } return -1;

12
New cards

ArrayList Algorithms - Find Sum

For loop: int sum = 0; for (int i = 0; i < cars.size(); i++) { sum += cars.get(i).getWeight(); } System.out.println(sum);

13
New cards

Traversing ArrayLists

Enhanced for-loop: for (Car c : cars) { System.out.println(c.getName()); }

14
New cards

Traversing ArrayLists

Regular for-loop: for (int i = 0; i < cars.size(); i++) { System.out.println(cars.get(i).getName()); }

15
New cards

Access (Arrays vs ArrayLists)

arr[0] vs arrayList.get(0)

16
New cards

Set item (Arrays vs ArrayLists)

arr[0] = "elephant" vs arrayList.set(0, "elephant")

17
New cards

Size (Arrays vs ArrayLists)

arr.length vs arrayList.size()

18
New cards

Initialize (Arrays vs ArrayLists)

String[] arr = {...} vs new ArrayList<String>()

19
New cards

Add item (Arrays vs ArrayLists)

Not allowed vs arrayList.add("giraffe")

20
New cards

Remove item (Arrays vs ArrayLists)

Not allowed vs arrayList.remove(0)

21
New cards

Array Algorithms - Find Average

For loop: double total = 0; for (int i = 0; i < items.length; i++) { total += items[i]; } System.out.println(total / items.length);

22
New cards

Array Algorithms - Find Item

For loop: boolean found = false; for (int i = 0; i < items.length; i++) { if (items[i] == 42) found = true; } System.out.println(found);

23
New cards

Array Algorithms - Find Max

For loop: int max = Integer.MIN_VALUE; for (int i = 0; i < items.length; i++) { if (items[i] > max) max = items[i]; } System.out.println(max);

24
New cards

Looping in Reverse (Array)

for (int i = animals.length - 1; i >= 0; i--) { System.out.println(animals[i]); }

25
New cards

For-each Loop (Enhanced For)

for (String animal : animals) { System.out.println(animal); }

26
New cards

For Loop with Index (Arrays)

for (int i = 0; i < animals.length; i++) { System.out.println(animals[i]); }