Java Collection Framework - AbstractSequentialList

Java Collection Framework - AbstractSequentialList


Posted in : Core Java Posted on : May 26, 2011 at 5:08 PM Comments : [ 0 ]

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 :

  1. add() 
  2.                         syntax : public void add (int index, E element)

  3. addAll()  
  4.                         syntax : public boolean addAll (int index, Collection<? extends E> c)

  5. iterator()
  6.                         syntax : public Iterator<E> iterator()

  7. listIterator() 
  8.                         syntax : public abstract ListIterator<E> listIterator (int index)

  9. remove()
  10.                         syntax : public E remove (int index)

  11. get()
  12.                         syntax : public E get (int index)

  13. set()
  14.                         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

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics