---
title: "charAt Method — AP Comp Sci A Definition & Exam Guide"
description: "charAt returns the char at a given index in a String. Learn how it works, why AP CSA's Quick Reference favors substring instead, and how indexing is tested."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/charat-method"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 1"
---

# charAt Method — AP Comp Sci A Definition & Exam Guide

## Definition

charAt(int index) is a Java String method that returns the single character (a char primitive) at the given index, where valid indices run from 0 to length() - 1. On AP CSA, you'll more often see substring(index, index + 1), since charAt is not on the exam's Java Quick Reference.

## What It Is

The charAt method is called on a [String object](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4 "fv-autolink") and hands back the character sitting at a specific [index](/ap-comp-sci-a/key-terms/index "fv-autolink"). Strings in Java are indexed starting at 0, so `"hello".charAt(0)` returns 'h' and `"hello".charAt(4)` returns 'o'. Ask for an index outside the range 0 to length() - 1 and Java throws a StringIndexOutOfBoundsException, the same rule EK 1.15.B.1 gives you for every String index operation.

Here's the AP-specific catch. charAt returns a **char**, a [primitive type](/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE "fv-autolink"), while the methods on the AP Java Quick Reference (length, substring, indexOf, equals, compareTo) work with Strings and ints. That's why College Board code almost always grabs a single character with `str.substring(i, i + 1)`, which returns a one-character **String** instead of a char. You should recognize charAt if it shows up, but when you write FRQ code, substring is the safe, Quick-Reference-approved move. Also remember EK 1.15.A.3: Strings are immutable, so charAt only reads a character. It can never change one.

## Why It Matters

charAt lives in Topic 1.15 (String Methods) in [Unit 1](/ap-comp-sci-a/unit-1 "fv-autolink"): Using Objects and Methods, supporting learning objective [AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 1.15.B, which asks you to call methods on String objects and determine the result. Understanding charAt locks in the two ideas that 1.15.B is really testing. First, zero-based indexing, where the last valid index is length() - 1, not length(). Second, the exact boundary where StringIndexOutOfBoundsException fires. Those two facts show up constantly in string-traversal code, which then carries forward into loops (Unit 2) and ArrayList/array algorithms (Unit 4). Even though charAt itself isn't on the Quick Reference, the indexing model behind it is everywhere on the exam.

## Connections

### substring method (Unit 1)

substring(i, i + 1) is the AP-sanctioned way to do what charAt does. The difference is the [return type](/ap-comp-sci-a/key-terms/return-type "fv-autolink"). charAt gives you a char like 'a', while substring gives you a one-character String like "a". Since the Quick Reference includes substring and not charAt, released FRQ solutions pull single characters with substring.

### [indexOf (Unit 1)](/ap-comp-sci-a/key-terms/indexof)

[indexOf](/ap-comp-sci-a/key-terms/indexof "fv-autolink") is the reverse operation. charAt takes an index and gives you the character there, while indexOf takes a String and tells you the index where it first appears (or -1 if it's not found). Pairing them mentally helps you read string-search code quickly.

### [string literal (Unit 1)](/ap-comp-sci-a/key-terms/string-literal)

Every charAt call happens on a String object, and EK 1.15.A.1 says those [objects](/ap-comp-sci-a/key-terms/object "fv-autolink") often come from string literals like "hello". Because Strings are immutable (EK 1.15.A.3), charAt can inspect the characters of a literal but never modify them.

### String traversal with loops (Unit 2)

The classic pattern is a for loop running i from 0 to str.length() - 1, grabbing one character per iteration. Whether the code uses charAt or substring(i, i + 1), the off-by-one logic is identical, and that loop boundary is exactly where exam questions try to trip you with a StringIndexOutOfBoundsException.

## On the AP Exam

charAt is not one of the String methods listed on the AP Java Quick Reference, so FRQs won't require it and official solutions use substring(i, i + 1) to get single characters. That said, you can use charAt correctly in your own FRQ code without penalty, and multiple-choice questions absolutely test the underlying skill it represents. Expect MCQ stems that ask you to trace string code and predict output, spot the index where a StringIndexOutOfBoundsException occurs, or determine what a loop builds character by character. The thing you must DO is apply zero-based indexing precisely. Know that valid indices run 0 through length() - 1, and know that charAt returns a char while substring returns a String, since mixing those types up breaks comparisons (you compare chars with ==, but Strings with equals).

## charAt method vs substring(i, i + 1)

Both pull out the single character at index i, but they return different types. charAt(i) returns a char primitive, so you compare results with == (like `s.charAt(0) == 'h'`). substring(i, i + 1) returns a String object, so you compare with equals (like `s.substring(0, 1).equals("h")`). On AP CSA, substring is the one on the Java Quick Reference, which is why exam code prefers it. Using == on the substring version or equals on a char is a classic trap answer in MCQs.

## Key Takeaways

- charAt(index) returns the char primitive at a given position in a String, with valid indices running from 0 to length() - 1.
- Calling charAt with an index outside that range throws a StringIndexOutOfBoundsException, per EK 1.15.B.1.
- charAt is not on the AP Java Quick Reference, so exam code typically uses substring(index, index + 1) instead, which returns a one-character String rather than a char.
- Compare chars with == but compare Strings with equals, so the return type of charAt versus substring actually changes how you write the comparison.
- charAt only reads characters and never changes them, because String objects are immutable (EK 1.15.A.3).

## FAQs

### What does the charAt method do in Java?

charAt(int index) is called on a String and returns the character at that index as a char primitive. For example, "java".charAt(2) returns 'v'. Indexing starts at 0 and the last valid index is length() - 1.

### Is charAt on the AP Computer Science A exam?

Not on the Java Quick Reference, no. The CED's required String methods are length, substring, indexOf, equals, and compareTo, so FRQs use substring(i, i + 1) to grab single characters. You can still use charAt in your own FRQ code, and MCQs may test the same indexing logic.

### What's the difference between charAt and substring?

charAt(i) returns a char primitive, while substring(i, i + 1) returns a one-character String. That changes how you compare the result: use == for the char and equals for the String. Functionally they extract the same character; only the type differs.

### Does charAt change the original String?

No. Strings in Java are immutable (EK 1.15.A.3), so no String method, including charAt, can modify the String it's called on. charAt just reads and returns one character.

### What happens if I call charAt with an index equal to the String's length?

You get a StringIndexOutOfBoundsException, because the last valid index is length() - 1, not length(). So "cat".charAt(3) crashes even though the String has 3 characters. This off-by-one boundary is a favorite MCQ trap.

## Related Study Guides

- [1.15 String Methods](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/charat-method#resource","name":"charAt Method — AP Comp Sci A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/charat-method","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/charat-method#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:20.024Z","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/charat-method#term","name":"charAt method","description":"charAt(int index) is a Java String method that returns the single character (a char primitive) at the given index, where valid indices run from 0 to length() - 1. On AP CSA, you'll more often see substring(index, index + 1), since charAt is not on the exam's Java Quick Reference.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/charat-method","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 the charAt method do in Java?","acceptedAnswer":{"@type":"Answer","text":"charAt(int index) is called on a String and returns the character at that index as a char primitive. For example, \"java\".charAt(2) returns 'v'. Indexing starts at 0 and the last valid index is length() - 1."}},{"@type":"Question","name":"Is charAt on the AP Computer Science A exam?","acceptedAnswer":{"@type":"Answer","text":"Not on the Java Quick Reference, no. The CED's required String methods are length, substring, indexOf, equals, and compareTo, so FRQs use substring(i, i + 1) to grab single characters. You can still use charAt in your own FRQ code, and MCQs may test the same indexing logic."}},{"@type":"Question","name":"What's the difference between charAt and substring?","acceptedAnswer":{"@type":"Answer","text":"charAt(i) returns a char primitive, while substring(i, i + 1) returns a one-character String. That changes how you compare the result: use == for the char and equals for the String. Functionally they extract the same character; only the type differs."}},{"@type":"Question","name":"Does charAt change the original String?","acceptedAnswer":{"@type":"Answer","text":"No. Strings in Java are immutable (EK 1.15.A.3), so no String method, including charAt, can modify the String it's called on. charAt just reads and returns one character."}},{"@type":"Question","name":"What happens if I call charAt with an index equal to the String's length?","acceptedAnswer":{"@type":"Answer","text":"You get a StringIndexOutOfBoundsException, because the last valid index is length() - 1, not length(). So \"cat\".charAt(3) crashes even though the String has 3 characters. This off-by-one boundary is a favorite MCQ trap."}}]},{"@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":"Unit 1","item":"https://fiveable.me/ap-comp-sci-a/unit-1"},{"@type":"ListItem","position":4,"name":"charAt method"}]}]}
```
