aımnova
DashboardMy LearningCrash CoursesStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Crash Courses
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Teachers
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aımnova

IB study, practice and feedback built around the real exam.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.c1e448f

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer Science HLTopic 6.2Arrays and lists
Back to Computer Science HL Topics
6.2.27 min read

Arrays and lists (Computer Science HL)

IB Computer Science · Unit 6

Exam preparation

Practice the questions examiners actually ask

Our question bank mirrors real IB exam papers. Practice under timed conditions and track your progress across topics.

Start Practicing

Contents

  1. 1Many values under one name
  2. 2Adding, removing, going through
  3. 3Two dimensions
  4. 4Exam-style question
The big idea: One variable holds one value. A list holds many, each reachable by its position.

That is what lets a loop handle a thousand items with the same three lines it uses for three.
marks = [72, 65, 91, 48]
#         0   1   2   3     ← positions

print(marks[0])       # 72   — the first, at position 0
print(marks[-1])      # 48   — the last
print(len(marks))     # 4

marks[1] = 70         # change one place
print(marks)          # [72, 70, 91, 48]
int[] marks = {72, 65, 91, 48};
//              0   1   2   3     ← positions

System.out.println(marks[0]);                  // 72   — the first, at position 0
System.out.println(marks[marks.length - 1]);   // 48   — the last
System.out.println(marks.length);              // 4

marks[1] = 70;                                 // change one place
System.out.println(Arrays.toString(marks));    // [72, 70, 91, 48]
Positions start at 0 here too: A list of four items has positions 0, 1, 2 and 3.

Asking for marks[4] is an error — and "off by one at the end" is the single commonest list bug.
Stopping an out-of-range index: Check an index before using it: if 0 <= i < len(marks) in Python, if (i >= 0 && i < marks.length) in Java.

Without the check, Python raises an IndexError and Java throws an ArrayIndexOutOfBoundsException, and the program stops.
Parallel arrays and arrays of objects: Two arrays can describe the same things position by position: names[3] and scores[3] belong to the same student. Sort or remove in one and the other must change the same way, or the pairs no longer match.

An array can also hold objects: points[2].getMemberId() calls the method of the object stored at index 2.

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime
names = ["Ana", "Ben"]

names.append("Cara")      # add at the end
names.insert(0, "Dai")    # add at a position
names.remove("Ben")       # remove by value
last = names.pop()        # remove the last and return it
print(names)              # ['Dai', 'Ana']

# Traversing — visiting every item in turn
for name in names:
    print(name)

# When you need the position as well:
for i in range(len(names)):
    print(i, names[i])
ArrayList<String> names = new ArrayList<>();
names.add("Ana");
names.add("Ben");

names.add("Cara");          // add at the end
names.add(0, "Dai");        // add at a position
names.remove("Ben");        // remove by value
String last = names.remove(names.size() - 1);   // remove the last and return it
System.out.println(names);  // [Dai, Ana]

// Traversing — visiting every item in turn
for (String name : names) {
    System.out.println(name);
}

// When you need the position as well:
for (int i = 0; i < names.size(); i++) {
    System.out.println(i + " " + names.get(i));
}

Adding

  • append — at the end, the cheapest place
  • insert(position, value) — anywhere, but everything after shifts along
  • Java's ArrayList uses add

Removing

  • remove(value) — the first matching item
  • pop() — the last item, and gives it back to you
  • pop(position) — a chosen position
  • Everything after a removal shifts down

Traversing

  • for item in list — when you only need the values
  • an index loop over the positions — when you need the position, not just the value
  • Never change a list's length while looping over it
Do not remove while you loop: Removing an item shifts everything after it down one place, while the loop's counter still moves up.

The result is that items get skipped, silently. Build a new list instead, or loop over a copy.
Older papers say "collection": Past papers before 2027 use the word collection for a list you add to and go through one item at a time. Today that is a Python list or a Java ArrayList: it changes size, keeps its items in order and has methods to add, remove and traverse.

Asked to draw an array? Draw one row of numbered boxes for each line of code, so every change is visible.

An array drawn as boxes, one row per line of code
How to draw an array after each line runs

Stop wasting time on topics you know

Our AI identifies your weak areas and focuses your study time where it matters. No more overstudying easy topics.

Try Smart Study FreeYour first topic is free to keep • No credit card required
A list of lists: A 2D list is a list whose items are themselves lists — a grid, with a row number and a column number.

Always in that order: [row][column].
grid = [[3, 8, 1],      # row 0
        [7, 2, 9],      # row 1
        [4, 6, 5]]      # row 2
#        c0 c1 c2

print(grid[1][2])       # 9   — row 1, column 2
print(grid[0])          # [3, 8, 1]  — a whole row

# Visiting every cell: one loop per dimension
total = 0
for row in grid:
    for value in row:
        total = total + value
print(total)            # 45
int[][] grid = {{3, 8, 1},      // row 0
                {7, 2, 9},      // row 1
                {4, 6, 5}};     // row 2
//               c0 c1 c2

System.out.println(grid[1][2]);                 // 9   — row 1, column 2
System.out.println(Arrays.toString(grid[0]));   // [3, 8, 1]  — a whole row

// Visiting every cell: one loop per dimension
int total = 0;
for (int[] row : grid) {
    for (int value : row) {
        total = total + value;
    }
}
System.out.println(total);                      // 45
1

Row first, always

grid[1][2] means row 1, column 2, giving 9.

Reversing them gives grid[2][1], which is 6 — a different cell, with no error to warn you.

2

A nested loop visits every cell

The outer loop takes each row; the inner loop takes each value in that row.

That is why scanning a grid is O(n²) — the work is rows times columns.

3

Rows and columns are not symmetric

A row is a real list, so grid[0] hands you one directly.

A column is not — reading column 2 means taking grid[r][2] from every row in turn.

How this is tested — you must get positions right and pick the correct traversal for the job. It comes up two ways:

Paper 2 — working with code

  • Construct code using a 1D or 2D list, 4-6 marks
  • Trace a loop over a list and state the output
  • Add, remove or search within a list

Paper 2 — the algorithmic-thinking question

  • Reason about a grid with no code shown
  • Explain why a traversal visits what it does
The classic trap: Removing items while looping over the list. Everything after the removal shifts down while the counter moves up, so items are skipped silently. Build a new list instead.
IB-style questionConstruct[6 marks]

A 2D list holds four students' marks in three subjects, one row per student. Write code to print each student's total and to find the highest single mark.

Model answer plan

See the answer broken into clear points, with guidance on how each point earns marks.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Arrays and lists. Write your answer and get instant AI feedback — just like a real IB examiner.

two operations commonly performed on an array. [1 mark]

Related Computer Science HL Topics

Continue learning with these related topics from the same unit:

6.1.1Variables and data types6.1.2Substrings6.1.3Exception handling6.1.4Debugging
View all Computer Science HL topics
Improve your exam techniqueCommand terms, paper structure, and mark-scheme tips for Computer Science HL
Previous6.2.1Static vs dynamic structuresNextStacks (LIFO)6.2.3

43 exam-style questions ready for you

Students who practice on Aimnova improve their scores by 15% on average. Get instant feedback that shows exactly how to improve your answers.

Practice Now — FreeView All Computer Science HL Topics