AbstractCollection class

AbstractCollection Java class is a part of the Collection Framework and implements the Collection interface.

AbstractCollection java

The AbstractCollection java class implements some methods of Collection interface and provides a skeletal implementation of the Collection interface. This clas uses to minimize the effort required to implement collection interface.

public abstract class AbstractCollection<E> implements Collection<E>

where E is the type of elements maintained by this collection.

How AbstractCollection class is useful?
1. Unmodifiable collection: Those collections
can’t be modified (like ImmutableList) are known as unmodified collection. To implement an unmodified collection the programmer needs only to extend AbstractCollection class and provide implementations for the iterator() and size() methods.
2. Modifiable collection: Those collection can be modified (like ArrayList) are known as modified collection. To implement a modified collection the programmer must additionally override the add() method. If the programmer doesn’t override the add() method, it throws an
UnsupportedOperationException.

Constructor: The default constructor, but being protected, it doesn’t allow to create an AbstractCollection object.

Leave a Comment