DEV Community

Cover image for Collection Interface - List
Ramya K
Ramya K

Posted on

Collection Interface - List

**
 **
The Collection interface is the root interface of the Java Collection Hierarchy. It is located in the java.util package. The Collection interface is not directly implemented by any class. Instead, it is implemented indirectly through its sub-interfaces like List, Queue, and Set.

*List: *
List is a subinterface of Collection and used when we want to store elements in a specific order and allow duplicates.

Key Features:
● ✅ Maintains the order of insertion
● ✅ Allows duplicate elements
● ✅ Supports null values (implementation-dependent)
● ✅ Provides index-based access (get, add, set, remove)
● ✅ Includes ListIterator for forward & backward traversal
● ✅ Implementation Classes: - ArrayList - LinkedList - Stack - Vector

ArrayList:
ArrayList is an implementing class of the List interface. It stores the element dynamically. It maintains insertion order, allows duplicates and null values.

✅ Key Features:
● Maintains insertion order
● Allows duplicate elements
● Allows null values
● Dynamic resizing (no fixed size)
● Index-based access (get/set)
● Not thread-safe (non synchronized)

✅ When to Use:
● When fast random access is needed.
● When mostly reading data.
● When adding/removing at the end.

✅ Important Points to Remember:
● Not suitable for multi-threading (use Collections.synchronizedList() or CopyOnWriteArrayList if needed)
● Faster than LinkedList in access
● Slower than LinkedList in insertion/deletion in the middle

✅ One-Line Summary:

ArrayList = Fast access + Dynamic Array + Allows duplicates & nulls + Not thread-safe

Top comments (0)