---
title: "Generic Type — AP Comp Sci A Definition & Exam Guide"
description: "A generic type like ArrayList<String> uses angle brackets to lock in an element type, letting the compiler catch type errors early. Core to Unit 4 ArrayLists."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/generic-type"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 4"
---

# Generic Type — AP Comp Sci A Definition & Exam Guide

## Definition

A generic type in AP Computer Science A is a class like ArrayList<E> whose angle-bracket type parameter E specifies the type of elements it holds, so methods like add() and get() accept and return that exact type and the compiler can catch type mismatches before the program runs.

## What It Is

A generic type is a Java [class](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") with a type parameter in angle brackets. On the AP exam, that means `ArrayList<E>`, where E is a placeholder you fill in when you create the [list](/ap-comp-sci-a/key-terms/list "fv-autolink"). Writing `ArrayList<String> names = new ArrayList<String>();` tells Java that this list holds Strings and nothing else. From that point on, every ArrayList method is locked to that type. `add()` only accepts Strings, and `get()` hands back a String you can use immediately, no casting required.

The payoff is **compile-time type safety**. Per EK 4.8.A.3, `ArrayList<E>` is preferred over plain `ArrayList` because the compiler can find type errors that would otherwise only show up as crashes at [run-time](/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ "fv-autolink"). Think of the angle brackets as a label on a storage bin. Without the label, you find out something wrong is in the bin only when you reach in and get surprised. With the label, Java refuses to let the wrong item in at all.

## Why It Matters

Generic types live in **Topic 4.8 (ArrayList Methods)** in **[Unit 4](/ap-comp-sci-a/unit-4 "fv-autolink"): Data Collections**, supporting learning objective **[AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 4.8.A**, which asks you to develop code using ArrayList objects and determine the result of calling their methods. You can't do either of those without reading the generic type. The `<E>` tells you what `get()` returns, what `add()` accepts, and whether a code segment even compiles. Since Unit 4 carries heavy weight on both the multiple-choice section and the array/ArrayList FRQ, the `ArrayList<Type>` declaration is something you'll write or interpret on nearly every collections question.

## Connections

### [.get() method (Unit 4)](/ap-comp-sci-a/key-terms/get-method)

The generic type is what makes get() useful. If the list is declared ArrayList<String>, then list.get(0) returns a String you can call String methods on directly. With a raw ArrayList, you'd just get a generic [Object](/ap-comp-sci-a/key-terms/object "fv-autolink") back.

### [Object reference (Unit 4)](/ap-comp-sci-a/key-terms/object-reference)

Per EK 4.8.A.1, an ArrayList stores [object references](/ap-comp-sci-a/key-terms/object-reference "fv-autolink"), not the objects themselves. The generic type tells you what kind of object those references point to. This is also why you can't write ArrayList<int>; the type parameter must be a class like Integer, since primitives aren't objects.

### [ArrayList constructor (Unit 4)](/ap-comp-sci-a/key-terms/arraylist-constructor)

EK 4.8.A.2's constructor pairs with the generic type in one line. The declaration ArrayList<String> names = new ArrayList<String>(); builds an empty list that the [compiler](/ap-comp-sci-a/key-terms/compiler "fv-autolink") treats as String-only from the very first add() call.

## On the AP Exam

Generic types show up the moment any question instantiates an ArrayList. A common multiple-choice setup gives you a code segment with `/* missing code */` and asks which declaration correctly creates the list, for example picking `ArrayList<String> list = new ArrayList<String>();` over options with wrong syntax or mismatched types. You also need to trace what `get()` returns based on the declared type parameter. On the free-response section, the array/ArrayList question expects you to declare lists with the correct generic type yourself. Writing a raw `ArrayList` instead of `ArrayList<E>` is exactly the kind of thing the CED says to avoid, so always include the angle brackets.

## generic type vs Raw ArrayList (no type parameter)

A raw ArrayList compiles, but it treats every element as a plain Object, so type mistakes only blow up at run-time. ArrayList<E> moves that error to compile-time. EK 4.8.A.3 is explicit that ArrayList<E> is preferred. Same class, but the angle brackets are the difference between the compiler protecting you and a surprise crash.

## Key Takeaways

- A generic type uses angle brackets, like ArrayList<String>, to specify exactly what type of elements a collection holds.
- When you declare ArrayList<E>, the ArrayList methods' parameter types and return types all become type E, so get() returns that type with no casting.
- ArrayList<E> is preferred over raw ArrayList because the compiler catches type errors that would otherwise crash the program at run-time.
- The type parameter must be a class, not a primitive, because an ArrayList stores object references (so use Integer, not int).
- The standard exam-ready declaration is ArrayList<Type> name = new ArrayList<Type>(); and you should write it this way on the FRQs.

## FAQs

### What is a generic type in AP Computer Science A?

It's a class with a type parameter in angle brackets, like ArrayList<E>, where E names the element type. Declaring ArrayList<String> means the list only holds Strings, and methods like add() and get() work with Strings specifically.

### Can you use int as a generic type, like ArrayList<int>?

No. ArrayLists store object references, and int is a primitive, not an object. Use the Integer wrapper class instead, as in ArrayList<Integer>.

### Is ArrayList without angle brackets wrong on the AP exam?

It compiles, but the CED (EK 4.8.A.3) says ArrayList<E> is preferred because the compiler can catch type errors that a raw ArrayList would only reveal at run-time. Always write the angle brackets on FRQs.

### What's the difference between ArrayList<E> and ArrayList<String>?

ArrayList<E> is the general form, where E is a placeholder type parameter. ArrayList<String> fills in that placeholder with an actual class, creating a list that holds only Strings. You write the filled-in version in real code.

### Why do generics matter for the get() method?

The generic type sets get()'s return type. With ArrayList<String>, list.get(0) returns a String you can use directly, like calling .length() on it. Without the type parameter, get() returns Object and you lose that compile-time guarantee.

## Related Study Guides

- [4.8 ArrayList Methods](/ap-comp-sci-a/unit-4/arraylist-methods/study-guide/8juIkbLwLGELYtblBeCf)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/generic-type#resource","name":"Generic Type — AP Comp Sci A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/generic-type","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/generic-type#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:18.673Z","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/generic-type#term","name":"generic type","description":"A generic type in AP Computer Science A is a class like ArrayList<E> whose angle-bracket type parameter E specifies the type of elements it holds, so methods like add() and get() accept and return that exact type and the compiler can catch type mismatches before the program runs.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/generic-type","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 is a generic type in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"It's a class with a type parameter in angle brackets, like ArrayList<E>, where E names the element type. Declaring ArrayList<String> means the list only holds Strings, and methods like add() and get() work with Strings specifically."}},{"@type":"Question","name":"Can you use int as a generic type, like ArrayList<int>?","acceptedAnswer":{"@type":"Answer","text":"No. ArrayLists store object references, and int is a primitive, not an object. Use the Integer wrapper class instead, as in ArrayList<Integer>."}},{"@type":"Question","name":"Is ArrayList without angle brackets wrong on the AP exam?","acceptedAnswer":{"@type":"Answer","text":"It compiles, but the CED (EK 4.8.A.3) says ArrayList<E> is preferred because the compiler can catch type errors that a raw ArrayList would only reveal at run-time. Always write the angle brackets on FRQs."}},{"@type":"Question","name":"What's the difference between ArrayList<E> and ArrayList<String>?","acceptedAnswer":{"@type":"Answer","text":"ArrayList<E> is the general form, where E is a placeholder type parameter. ArrayList<String> fills in that placeholder with an actual class, creating a list that holds only Strings. You write the filled-in version in real code."}},{"@type":"Question","name":"Why do generics matter for the get() method?","acceptedAnswer":{"@type":"Answer","text":"The generic type sets get()'s return type. With ArrayList<String>, list.get(0) returns a String you can use directly, like calling .length() on it. Without the type parameter, get() returns Object and you lose that compile-time guarantee."}}]},{"@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 4","item":"https://fiveable.me/ap-comp-sci-a/unit-4"},{"@type":"ListItem","position":4,"name":"generic type"}]}]}
```
