wellnwill Marathahalli Bangalore

List

List interface is available in java.util package and extends Collection interface. It provides the following functionalities to sub classes.

The elements are stored based on index. We can access any element directly based on specified index.

List subclasses allows duplicates and null values.

Reverse direction traversing is possible.

We can insert elements either at the end of List object or at specific index.

Commonly used methods of List interface:

public object get(int index):

This method is used to get element from the specified index.

public object set(int index, Object element):

This method is used to replace the existing element from List with given element from specified index.

public void add(int index,Object element):

This method is used to insert the element at specified index.

public void addAll(int index,Collection c):

This method is used to insert the elements of specified collection object to current object at specified index.

public void remove(int index):

This method is used to remove the element at specified index.

public int indexOf(Object element):

This method is used to return the first occurrence of specified element.

public int lastIndexOf(Object element):

This method is used to return the last occurrence of specified element.

public ListIterator listIterator():

This method is used for accessing the data from List object either in forward or in backward.

public ListIterator listIterator(int index):

This method is used for accessing the data from List object that points to specified index.

ListIterator interface:

ListIterator interface provides the facility for traversing the List objects either in forward or in backward direction.

ListIterator interface has following methods

public boolean hasNext():

This method is used to check whether next element is available or not in the List object. If next element present in the List then it returns true otherwise it returns false.

public Object next():

This method is used to retrieve the next element in the collection object.

public boolean hasPrevious():

This method is used to check whether previous element is available or not in the List object. If previous element present in the List then it returns true otherwise it returns false.

public Object previous():

This method is used to retrieve the previous element in the collection object.

Footer with Map