Quick revision
The short answer
Skeletal implementation classes such as AbstractCollection, AbstractList, AbstractSet and AbstractMap implement most of an interface in terms of a few primitive methods, so a new collection needs only a handful of lines: AbstractList needs get and size for a read-only list, plus set for a fixed-size one and add and remove by index for a growable one. The methods we do not override are the optional operations, which by default throw UnsupportedOperationException; unmodifiable and fixed-size collections such as Arrays.asList use exactly that to reject changes.
What to remember
In this answer, we saw that skeletal classes like AbstractList implement most of an interface on top of a few primitives, so a custom list needs only get and size, and set, add and remove when it must be modifiable. The methods we leave out are optional operations that throw UnsupportedOperationException, which is how unmodifiable collections and fixed-size lists like Arrays.asList refuse changes. The design keeps the framework small with one interface per concept, at the cost of finding mutability mistakes at run time instead of compile time.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Skeletal implementation classes such as AbstractCollection, AbstractList, AbstractSet and AbstractMap implement most of an interface in terms of a few primitive methods, so a new collection needs only a handful of lines: AbstractList needs get and size for a read-only list, plus set for a fixed-size one and add and remove by index for a growable one. The methods we do not override are the optional operations, which by default throw UnsupportedOperationException; unmodifiable and fixed-size collections such as Arrays.asList use exactly that to reject changes.
Why this question is asked
Most of us never write our own List, but we use collections built this way all the time: Arrays.asList, the views from subList and keySet, Collections.unmodifiableList. Knowing the skeletal classes explains why some of these throw UnsupportedOperationException and others do not, and it lets us write an efficient custom view in ten lines when a real problem calls for one. Interviewers ask this because it tests whether we understand the design of the framework rather than only its classes. In this answer, we will see what problem the skeletal classes solve, build a custom list on AbstractList, look at the optional operations, and discuss the price of this design.
1The Problem the Skeletal Classes Solve
The List interface has more than thirty methods: contains, indexOf, lastIndexOf, iterator, listIterator, subList, equals, hashCode, toString, containsAll, toArray and so on. Writing all of them correctly for every new list would be slow and error-prone. Yet almost all of them can be built from two basic operations: get the element at an index, and know the size.
That is what a skeletal implementation does. It is an abstract class that implements the interface, leaves a few primitive methods abstract, and writes every other method using those primitives. This pattern, an interface paired with an abstract skeletal class, is used throughout the JDK. AbstractCollection needs iterator() and size(). AbstractList needs get(int) and size(). AbstractSequentialList, for lists without fast index access, needs listIterator and size. AbstractSet adds the Set version of equals and hashCode, and AbstractMap needs only entrySet().
| Class | Read-only needs | Modifiable also needs |
|---|---|---|
AbstractCollection | iterator(), size() | add(E); iterator's remove() |
AbstractList | get(int), size() | set(int, E); add(int, E), remove(int) to grow or shrink |
AbstractSequentialList | listIterator(int), size() | the list iterator's set, add, remove |
AbstractSet | iterator(), size() | add(E); iterator's remove() |
AbstractMap | entrySet() | put(K, V); entry set iterator's remove() |
2Building a Read-Only List in Ten Lines
Suppose we need a list of the integers from 10 to 14, but the real use case is a range of a million numbers, and we do not want to allocate a million Integer objects up front. AbstractList lets us compute each element on demand.
We wrote two methods and received the whole List contract: iteration, search, sublists, streams, and correct equals and hashCode, which means our range compares equal to any other List with the same elements. Notice the last two lines. We never wrote add or set, and AbstractList's versions simply throw UnsupportedOperationException. That is not a bug; it is how the framework expresses that this list does not support those operations.
3What the Optional Operations Are
The Javadoc of Collection marks several methods as optional operations: add, addAll, remove, removeAll, retainAll, removeIf and clear, and List adds set, add(int, E) and remove(int). An implementation may choose not to support them. If it does not, calling them must throw UnsupportedOperationException, an unchecked exception.
This gives three common levels of mutability, all sharing the same interfaces. An unmodifiable collection, such as List.of(1, 2) or Collections.unmodifiableList(x), throws for every mutator. A fixed-size list, such as Arrays.asList, allows set but throws for anything that changes the size. A fully modifiable collection, such as ArrayList, supports everything.
Arrays.asList shows why the fixed-size level exists. The list is a thin view over the array we passed in, so replacing an element is easy, but the array cannot grow or shrink, and the list says so by throwing. In AbstractList terms, it overrides get, size and set, but not add(int, E) or remove(int).
4The Price of This Design
The alternative would have been separate interfaces: a ReadableList, a FixedSizeList, a ModifiableList, and then the same split for sets, maps and queues, and again for views of each. The designers judged that this would multiply the number of interfaces many times over, make the framework harder to learn, and still not cover every case, such as append-only lists or lists that allow removal but not addition. So they kept one interface per concept and let implementations refuse what they do not support.
The price is that the compiler cannot help us. A method that receives a List<String> cannot tell from the type whether add will work. The error appears only at run time, often far from where the unmodifiable list was created. So we compensate with documentation and habits: a method should say whether it returns a modifiable list, and code that needs to modify a list it received should copy it first, new ArrayList<>(input), rather than assume.
5Follow-up questions
If I extend AbstractList, what else should I consider overriding?
The inherited methods are correct but not always fast. contains and indexOf scan from the start, which is fine for most lists, but our IntRange could answer contains in constant time with a simple range check. It is common to override such methods when the data structure allows a faster answer. If get is not fast, extend AbstractSequentialList instead.
Does AbstractList give fail-fast iterators?
Yes, if we update the protected modCount field whenever the list changes size. The iterator compares modCount with the value it saw at the start and throws ConcurrentModificationException if they differ. A read-only list never changes, so it can ignore modCount.
Is an unmodifiable view the same as an immutable list?
No. Collections.unmodifiableList blocks changes through the view, but if someone still holds the original list and changes it, the view shows those changes. List.of and List.copyOf create lists whose contents cannot change at all.
6Conclusion
In this answer, we saw that skeletal classes like AbstractList implement most of an interface on top of a few primitives, so a custom list needs only get and size, and set, add and remove when it must be modifiable. The methods we leave out are optional operations that throw UnsupportedOperationException, which is how unmodifiable collections and fixed-size lists like Arrays.asList refuse changes. The design keeps the framework small with one interface per concept, at the cost of finding mutability mistakes at run time instead of compile time.
Open with
The skeletal classes, like AbstractCollection, AbstractList, AbstractSet and AbstractMap, exist so we can write a new collection with very little code. Each one implements the interface in terms of a few primitives.
Then, if they want more
For a read-only list, AbstractList only needs get and size, and from those it gives me iteration, contains, indexOf, subList, equals, hashCode and toString. If I also implement set, I have a fixed-size list, and if I implement add and remove by index, the list can grow and shrink. AbstractMap only needs entrySet.
Whatever I do not implement falls back to a default that throws UnsupportedOperationException, and that ties into the optional operations: the Collection interface marks methods like add, remove and clear as optional, so an implementation can refuse them.
That is how List.of and unmodifiable views reject every change, and how Arrays.asList, which is a fixed-size view over an array, lets you call set but throws on add or remove.
The reason for this design is to keep one interface per concept instead of separate read-only, fixed-size and modifiable interfaces for every collection type, which would have multiplied the API.
The cost is that mutability is not in the type, so these errors show up at run time, which is why I document whether returned lists are modifiable and copy inputs before changing them.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Collections Framework, overview, java.util, package documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What are the skeletal implementation classes such as AbstractList and AbstractMap for...": https://scrivio-interview-library.netlify.app/java/collections-overview/e40315bbe2/