---
title: "Immutable — AP Computer Science A Definition & Exam Guide"
description: "Immutable means an object can't change after creation. In AP CSA, Strings are immutable, so every \"change\" actually creates a brand-new String object."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/immutable"
type: "key-term"
subject: "AP Computer Science A"
---

# Immutable — AP Computer Science A Definition & Exam Guide

## Definition

In AP Computer Science A, immutable means an object's state cannot be changed after it's created; the classic example is the String class, where methods like substring and concat never alter the original String but instead return a new String object.

## What It Is

Immutable describes an [object](/ap-comp-sci-a/key-terms/object "fv-autolink") whose internal state is locked in the moment it's constructed. You can read it, copy it, and call [methods](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") on it, but nothing can rewrite what's inside. If you want a "changed" version, you don't edit the original. You get a whole new object back.

In AP CSA, the star example is the **String class**. When you call `str.substring(0, 3)` or `str.toUpperCase()`, the original String sitting in memory is untouched. Java builds a fresh String containing the result and hands it to you. That's why a line like `str.toUpperCase();` by itself does nothing useful. You have to capture the return value, like `str = str.toUpperCase();`, which makes the [variable](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") point to the new object. The old String didn't change. Your reference just moved.

## Why It Matters

Immutability shows up the moment you start using objects in [Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink"), because the CED's essential knowledge about the String class explicitly treats Strings as immutable. Every String method that looks like it "modifies" a String actually returns a new one. This single fact explains a huge family of [tracing](/ap-comp-sci-a/key-terms/tracing "fv-autolink") mistakes. If you forget it, you'll predict that `s.concat("!")` changed `s`, and you'll miss easy multiple-choice points. It also sets up a bigger idea you carry into Units 5-7: some objects (Strings, wrapper objects like Integer) are frozen, while others (arrays, ArrayLists, your own classes with mutator methods) can be changed in place. Knowing which is which tells you whether a method call can have side effects on the caller's data, which matters for writing and reading FRQ code.

## Connections

### String Class (Unit 2)

Strings are THE immutable object on the AP exam. Methods like [substring](/ap-comp-sci-a/unit-2/developing-algorithms-using-strings/study-guide/hDOL1VhnMQFPkBf6xMMW "fv-autolink"), concat, and toUpperCase return new Strings, so the original never changes unless you reassign the variable to the result.

### [Final Keyword (Units 1 & 5)](/ap-comp-sci-a/key-terms/final-keyword)

These get mixed up constantly. final freezes a variable so it can't be reassigned to a different object, while immutable freezes the object itself. A final ArrayList variable can still have elements added to it, because the [list](/ap-comp-sci-a/key-terms/list "fv-autolink") object is mutable even though the reference is locked.

### Mutable (Units 6 & 7)

Mutable is the direct opposite. Arrays and ArrayLists can be changed in place, so `list.add(x)` or `arr[0] = 5` really does modify the original object. When a [mutable object](/ap-comp-sci-a/key-terms/mutable-object "fv-autolink") is passed to a method, changes inside the method stick. With an immutable String, they can't.

## On the AP Exam

Immutability is mostly tested through String tracing in multiple choice. A classic stem gives you code like `String s = "hello"; s.substring(0, 3);` and asks what `s` holds afterward. The answer is still "hello", because substring returned a new String that was never stored. On FRQs, immutability shows up whenever you write string-building code. You can't edit a String in a loop, so the standard pattern is building up a result with reassignment, like `result = result + nextPart;` or `result += word.substring(1);`. Forgetting to reassign is one of the most common point-losing mistakes in string-manipulation FRQs. No released FRQ asks you to define "immutable" directly, but the concept is baked into nearly every question that touches Strings.

## Immutable vs Final Keyword

final and immutable lock different things. final locks the variable, meaning the reference can never be reassigned to point at a different object. Immutable locks the object, meaning its contents can never change. The two are independent. A final variable can point to a mutable ArrayList that you freely add to, and a non-final String variable can be reassigned all day even though each individual String object is immutable. Quick test: ask "can the object's contents change?" (immutability) versus "can the variable point somewhere new?" (final).

## Key Takeaways

- Immutable means an object's state cannot be changed after it is created, and in AP CSA the most important immutable class is String.
- String methods like substring, concat, and toUpperCase never modify the original String; they return a brand-new String object.
- Calling a String method without storing the result, like `s.toUpperCase();`, does nothing. You must reassign, like `s = s.toUpperCase();`.
- Immutable is about the object, while the final keyword is about the variable. A final reference to a mutable object can still have its contents changed.
- Arrays and ArrayLists are mutable, so methods can change their contents through a reference, which is impossible with an immutable String.

## FAQs

### What does immutable mean in AP Computer Science A?

Immutable means an object cannot be changed after it's created. In AP CSA the key example is the String class, where every "modifying" method actually returns a new String instead of editing the original.

### Does str += "x" change the original String in Java?

No. Since Strings are immutable, `str += "x"` creates a brand-new String containing the combined text and makes the variable `str` point to it. The original String object is never modified.

### Is final the same as immutable in Java?

No. final means a variable can't be reassigned to a different object, while immutable means the object itself can't change. A final ArrayList can still have elements added or removed because the list object is mutable.

### Are arrays and ArrayLists immutable in Java?

No, both are mutable. You can change an array element with `arr[i] = value` and modify an ArrayList with methods like add, set, and remove, all of which affect the original object.

### Why does s.substring(0, 3) not change the String s?

Because Strings are immutable, substring builds and returns a new String containing characters 0 through 2 and leaves `s` untouched. To keep the result, write `s = s.substring(0, 3);` so the variable points to the new String.

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/immutable#resource","name":"Immutable — AP Computer Science A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/immutable","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/immutable#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-12T22:52:43.598Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/immutable#term","name":"Immutable","description":"In AP Computer Science A, immutable means an object's state cannot be changed after it's created; the classic example is the String class, where methods like substring and concat never alter the original String but instead return a new String object.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/immutable","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What does immutable mean in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"Immutable means an object cannot be changed after it's created. In AP CSA the key example is the String class, where every \"modifying\" method actually returns a new String instead of editing the original."}},{"@type":"Question","name":"Does str += \"x\" change the original String in Java?","acceptedAnswer":{"@type":"Answer","text":"No. Since Strings are immutable, `str += \"x\"` creates a brand-new String containing the combined text and makes the variable `str` point to it. The original String object is never modified."}},{"@type":"Question","name":"Is final the same as immutable in Java?","acceptedAnswer":{"@type":"Answer","text":"No. final means a variable can't be reassigned to a different object, while immutable means the object itself can't change. A final ArrayList can still have elements added or removed because the list object is mutable."}},{"@type":"Question","name":"Are arrays and ArrayLists immutable in Java?","acceptedAnswer":{"@type":"Answer","text":"No, both are mutable. You can change an array element with `arr[i] = value` and modify an ArrayList with methods like add, set, and remove, all of which affect the original object."}},{"@type":"Question","name":"Why does s.substring(0, 3) not change the String s?","acceptedAnswer":{"@type":"Answer","text":"Because Strings are immutable, substring builds and returns a new String containing characters 0 through 2 and leaves `s` untouched. To keep the result, write `s = s.substring(0, 3);` so the variable points to the new String."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Immutable"}]}]}
```
