AbstractSequentialList in Java with Examples

The AbstractSequentialList class in Java is a part of the Java Collection Framework and implements the Collection interface and the AbstractCollection class. It is used to implement an unmodifiable list, for which one needs to only extend this AbstractList Class and implement only the get() and the size() methods.

Class Hierarchy:

 ↳ java.util.AbstractCollection<E>
    ↳ java.util.AbstractList<E>
      ↳ java.util.AbstractSequentialList<E>


public abstract class AbstractSequentialList<E>
    extends AbstractList<E>

Where E is the type of element maintained
by this List.

Constructors in Java AbstractSequentialList:

  • protected AbstractSequentialList(): The default constructor, but being protected, it doesn’t allow to create an AbstractSequentialList object.

Below is a sample program to illustrate AbstractSequentialList in Java:

// Java code to illustrate AbstractSequentialList
import java.util.*;
public class GfG {
    public static void main(String[] args)
        // Creating an instance of the AbstractSequentialList
            absl = new LinkedList<>();
        // adding elements to absl
        // Printing the list


[5, 6, 7]

Methods in Java AbstractList:

  1. add(int index, E element): Inserts the specified element at the specified position in this list (optional operation).
  2. addAll(int index, Collection c): Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
  3. get(int index): Returns the element at the specified position in this list.
  4. iterator(): Returns an iterator over the elements in this list (in proper sequence).
  5. listIterator(int index): Returns a list iterator over the elements in this list (in proper sequence).
  6. remove(int index): Removes the element at the specified position in this list (optional operation).
  7. set(int index, E element): Replaces the element at the specified position in this list with the specified element (optional operation).


// Java code to illustrate
// methods of AbstractSequentialList
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
    public static void main(String args[])
        // Creating an empty AbstractSequentialList
            absqlist = new LinkedList<String>();
        // Using add() method to add elements in the list
        // Output the list
        System.out.println("AbstractSequentialList: "
                           + absqlist);
        // Remove the head using remove()
        // Print the final list
        System.out.println("Final List: "
                           + absqlist);
        // Fetching the specific element from the list
        // using get() method
        System.out.println("The element is: "
                           + absqlist.get(2));


AbstractSequentialList: [Geeks, for, Geeks, 10, 20]
Final List: [Geeks, for, Geeks, 20]
The element is: Geeks

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/AbstractSequentialList.html

This article is attributed to GeeksforGeeks.org

leave a comment



load comments

Subscribe to Our Newsletter