Categories: Java

AbstractSequential List in Java

The Java Collection Framework includes the AbstractSequential List class, which 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.

AbstractSequential List Method:
MethodDescription
add(int index, E element)Inserts the specified element into this list at the specified position (optional operation).
addAll(int index, Collection c)Inserts all the elements from the specified collection at the specified position into this list (optional operation).
get(int index)The element at the specified position in this list is returned.
iterator()Iterates through the elements in this list (in proper sequence).
listIterator(int index)Returns a list iterator over the list’s elements (in proper sequence).
remove(int index)The element at the specified position in this list is removed (optional operation).
set(int index, E element)Replaces the element at the specified position in this list with the specified element (optional operation).
Example:


import java.util.*;
import java.util.AbstractSequentialList;

public class Coderz {
 public static void main(String args[])
 {

  // Creating an empty AbstractSequentialList
  AbstractSequentialList<String>
   abs = new LinkedList<String>();

  // Using add() method to
  // add elements in the list
 abs.add("Accessories");
      abs.add("Home Decor");
      abs.add("Books");
      abs.add("Stationery");
      abs.add("Appliances");
      abs.add("Toys");

  // Output the list
  System.out.println("AbstractSequentialList: "
      + abs);

  // Remove the head using remove()
  abs.remove(3);

  // Print the final list
  System.out.println("Final List: "
      + abs);

  // Fetching the specific
  // element from the list
  // using get() method
  System.out.println("The element is: "
      + abs.get(2));
 }
}
Output:
AbstractSequentialList: [Accessories, Home Decor, Books, Stationery, Appliances, Toys]
Final List: [Accessories, Home Decor, Books, Appliances, Toys]
The element is: Books

Note: also read about the Abstract List in Java

Follow Me

If you like my post, please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

1 year ago