Tuesday 25 March 2014

List Interface


List is an ordered collection of elements. Unlike Set, List allows duplicates. You can access the elements in the list by index.

The List interface provides a ListIterator that allows element insertion and replacement, and provides bidirectional access to the elements in the list .

List interface extends the Collection interface.

ArrayList, LinkedList and Vector are the basic classes which implement List interface.

As Compared to set, List perform below operations
  1. Allows Duplicates
  2. Provides ListIterator for bidirectional traversal
  3. can add element at particular index
  4. Get the elements based on the index position
  5. Add collection of elements at particular index
  6. Remove element at particular index.
  7. Get the first and last index of element

public interface List<E> extends Collection<E>{
 int size();
 boolean isEmpty();
 boolean contains(Object o);
 Iterator<E> iterator();
 Object[] toArray();
 <T> T[] toArray(T[] a);
 boolean add(E e);
 boolean remove(Object o);
 boolean containsAll(Collection<?> c);
 boolean addAll(Collection<? extends E> c);
 boolean addAll(int index, Collection<? extends E> c);
 boolean removeAll(Collection<?> c);
 boolean retainAll(Collection<?> c);
 void clear();
 boolean equals(Object o);
 int hashCode();
 E get(int index);
 E set(int index, E element);
 void add(int index, E element);
 E remove(int index);
 int indexOf(Object o);
 int lastIndexOf(Object o);
 ListIterator<E> listIterator();
 ListIterator<E> listIterator(int index);
 List<E> subList(int fromIndex, int toIndex);
}


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment