AbstractSequentialList class is an abstract class and it extends the class AbstractList. This class reduces the effort needed to implement List interface returned by a 'sequential access' data store.
Java Collection Framework - AbstractSequentialList
AbstractSequentialList class is an abstract class and it extends the class AbstractList. This class reduces the effort needed to implement List interface returned by a 'sequential access' data store. To implement a list there is just required to extend the AbstractSequentialList class and allows the implementations for the methods listIterator and size. In an unmodifiable list the programmers have just required to apply the hasNext, next, hasPrevious, previous, and index methods of list iterator. But in a modifiable list there should be the set method of list iterator apply additionally. This class is a part of Java collection framework and is available in java.util package.
Syntax
public abstract class AbstractSequentialList<E> extends AbstractList<E>
Constructor of AbstractSequentialList
protected AbstractSequentialList() : The only constructor of this class which is implicitly invoked by the subclass constructor.
Methods of AbstractSequentialList
The methods of AbstractSequentialList are :
- add()
- addAll()
- iterator()
- listIterator()
- remove()
- get()
- set()
syntax : public void add (int index, E element)
syntax : public boolean addAll (int index, Collection<? extends E> c)
syntax : public Iterator<E> iterator()
syntax : public abstract ListIterator<E> listIterator (int index)
syntax : public E remove (int index)
syntax : public E get (int index)
syntax : public E set (int index, E element)
Example
package devmanuals.com; import java.util.AbstractSequentialList; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; public class AbstractSequentialListDemo extends AbstractSequentialList { List list; AbstractSequentialListDemo(){ list=new LinkedList(); } public void add(int i){ list.add(i); System.out.println(list); } public ListIterator listIterator(int i) { ListIterator li=list.listIterator(); while(li.hasNext()){ System.out.println(li.next()); } return null; } public int size() { System.out.println(list.size()); return 0; } public static void main(String... args){ AbstractSequentialListDemo asl=new AbstractSequentialListDemo(); System.out.println("List = "); for(int i=5; i>=0; i--) asl.add(i); System.out.println("Size of list ="); asl.size(); System.out.println("Displaying list using listIterator"); asl.listIterator(); } }
Output :
List = [5] [5, 4] [5, 4, 3] [5, 4, 3, 2] [5, 4, 3, 2, 1] [5, 4, 3, 2, 1, 0] Size of list = 6 Displaying list using listIterator 5 4 3 2 1 0 |
[ 0 ] Comments