Java List Interface
List Interface is the subinterface of Collection.It contains methods to insert and delete elements in index basis.It is a factory of ListIterator interface.
Commonly used methods of List Interface:
- public void add(int index,Object element);
- public boolean addAll(int index,Collection c);
- public object get(int Index position);
- public object set(int index,Object element);
- public object remove(int index);
- public ListIterator listIterator();
- public ListIterator listIterator(int i);
Java ListIterator Interface
ListIterator Interface is used to traverse the element in backward and forward direction.
Commonly used methods of ListIterator Interface:
- public boolean hasNext();
- public Object next();
- public boolean hasPrevious();
- public Object previous();
Example of ListIterator Interface:
Output:element at 2nd position: Vijay
traversing elements in forward direction...
Amit
Sachin
Vijay
Kumar
traversing elements in backward direction...
Kumar
Vijay
Sachin
Amit
No comments:
Post a Comment