In this tutorial, we are going to discuss List interface in java. The List interface provides a way to store the ordered collection.
- It is the child interface of Collection.
- Suppose we want to represent a group of individual objects as a single entity where duplicates are allowed, and insertion order is preserved. Then we should go for List.
- Insertion order will be preserved by means of Index.
- We can differentiate duplicate objects and maintain insertion order using Index; hence “index plays a very important role in List.”
- List interface defines the following specific methods.
boolean add(int index,Object o); boolean addAll(int index,Collectio c); Object get(int index); Object remove(int index); Object set(int index,Object new); //to replace int indexOf(Object o); // Returns index of first occurrence of "o". int lastIndexOf(Object o); ListIterator listIterator();
List interface contains 4 classes