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.
Method | Description |
---|---|
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). |
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));
}
}
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
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
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…