A list is an ordered collection sometimes is also known as sequence. List may have contains duplicate values.
AbstractList is an abstract class which implements List interface. ArrayList, LinkedList, Vector are the concrete sub class of AbstractList.
As List interface implements the root interface (which is Collection) it has all the methods of Collection interface but also some new methods are there which is listed below:
AbstractList is an abstract class which implements List interface. ArrayList, LinkedList, Vector are the concrete sub class of AbstractList.
As List interface implements the root interface (which is Collection) it has all the methods of Collection interface but also some new methods are there which is listed below:
- void add(int index, Object data)
- void set(int index, Object data)
- Object get(int index)
- Object remove(int index)
- int indexOf(Object data)
- int lastIndexOf(Object data)
- List subList(int start, int end)
- ListIterator listIterator()
Now there is a method listIterator() which return the reference of ListIterator. We can also use the simple iterator() of the Collection interface. But the ListIterator have some of the extra facility provided which is not in the Iterator interface.
ListIterator Interface
ListIterator is an interface which extends from Iterator. Using the ListIterator we can also add, set elements at the specified position which is not possible in the Iterator interface.
We can also get an index of the next elements using ListIterator and also can get the previous element while iterating in forward direction.
We can also make iterations in backward directions, which is also not possible in Iterator interface.
Following is the list of the methods provided by ListIterator interface :
- hasNext()
- next()
- remove()
- previous()
- preivousIndex()
- nextIndex()
- add()
- set()
No comments:
Post a Comment