List Interface

List is a interface which extends Collection interface.

  1. In List duplicates are allowed and insertion order is preserved.
  2. List is index based so we can access, remove and add elements based on index.
  3. List allows multiple null insertions.
  4. List allows heterogeneous values

List interface is implemented by the ArrayList, LinkedList, Vector and Stack classes.

It has all the functionalities of Collection interface along with below functions.

  1. void add(index i, Object o): It is used for insert the element at the specified index.
  2. boolean addAll(index i, Collection c):Insert the collection in specified index.
  3. Object remove(index i):  Remove the element from the specified index and returns the removed element.
  4. Object get(index i): Get the element from the specified index.
  5. Object set(index i, Object o): Replaces the element in the specified index and returns the old element.
  6. int indexOf(Object o): returns the index of first occurrence of  given element. If element not found then returns -1.
  7. int lastIndexOf(Object 0): returns the index of last occurrence of given element.If element not found then returns -1.
  8. ListIterator listIterator(): it returns the iterator object.
  9. List subList(int minIndex, int maxIndex): Returns the sub list from the main list from mimIndex to maxIndex-1.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s