List Interface

List Interface –

            List interface is used for storing element as a sequence.  It means List maintain the sequence according to inserted order. List interface extends the Collection interface. List maintains the index of all elements. So you can insert and retrieve elements by their index.

            Keep in mind that list may contain duplicate elements.

            List interface has its own methods which described below –

void add(int index, Object obj) –
            This method is used for insert element at given position into the List. Element which is already exist on the given index automatically shifted up.

boolean addAll(int index, Collection c) –
            This method adds all the object of Collection c at given index and return true, otherwise return false in case of failure.

 Object get(int index) –
            This method return the element of given index.

int indexOf(Object obj) –
            This method return the inedx of given element.

int lastIndexOf(Object obj) –
            This method is used for return the last index of given element.

 ListIterator listIterator() –
            This method returns the iterator for all elements.

ListIterator listIterator(int index) –
            This method is used for iterator the element s from the given index.

 Object remove(int index) –
            This method is used for remove the particular element at given index and return the deleted object.

 Object set(int index, Object obj) –
            This method is used for add the object at given index, this method override the element if element is already on this position.

List subList(int start, int end) –
            This method is very important. This method gives this list of elements which is found in given range of index.

There are some classes which implements List Interface
  1. AbstractList
  2. AbstractSequentialList
  3. ArrayList
  4. AttributeList
  5. CopyOnWriteArrayList
  6. LinkedList
  7. RoleList
  8. RoleUnresolvedList
  9. Stack
  10. Vector