Course contentsShow
← Java
Lesson 857 of 2,87021. Generics FundamentalsFree lesson

Type Parameters: Naming Conventions (T, E, K, V)

Understand common conventions: T for type, E for element, K/V for key/value.

Type Parameters: Naming Conventions (T, E, K, V)

What you'll learn: How to recognize and use the standard single-letter names for generic type parameters in Java.

Why Naming Conventions Matter

When you declare a generic class, you choose names for your type parameters. While you could name them anything (MyType, Foo, Data), the Java community follows strong conventions using single uppercase letters. These conventions make generic code instantly recognizable and self-documenting.

The Standard Conventions

T - Type: The most common convention, used for a general-purpose type parameter. If your class needs just one generic type, T is the default choice.

E - Element: Used in collections to represent the element type. Think of a list or set—each item is an element.

K - Key and V - Value: Used together in map-like structures where you have key-value pairs.

N - Number: Sometimes used for numeric types, though less common than the others.

S, U, etc.: When you need multiple type parameters beyond the standard ones, continue with other letters.

Why These Letters?

Think of these as a shared language among Java developers. Just like variable names like i for loop counters, these single letters signal intent immediately. When you see List<E>, you know E stands for "Element." When you see Map<K, V>, you instantly recognize "Key" and "Value."

These aren't enforced by the compiler—they're purely conventional. But following them makes your code more readable to other Java developers who expect these patterns.

Examples of the Pattern

  • class Box<T> — a generic box holding any type
  • interface List<E> — a list of elements
  • interface Map<K, V> — a map with keys and values

Key Takeaway: Use T for general types, E for elements in collections, and K/V for key-value pairs—these single-letter conventions are the universal language of Java generics.