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.lang.Object ? java.util.AbstractCollection<E> ? java.util.AbstractList<E> ? java.util.AbstractSequentialList<E>
Syntax:
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:
filter_none
edit
play_arrow
brightness_4
|
Output:
[5, 6, 7]
Methods in Java AbstractList:
- add(int index, E element): Inserts the specified element at the specified position in this list (optional operation).
- addAll(int index, Collection c): Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
- get(int index): Returns the element at the specified position in this list.
- iterator(): Returns an iterator over the elements in this list (in proper sequence).
- list iterator(int index): Returns a list iterator over the elements in this list (in proper sequence).
- remove(int index): Removes the element at the specified position in this list (optional operation).
- set(int index, E element): Replaces the element at the specified position in this list with the specified element (optional operation).
Example:
filter_none
edit
play_arrow
brightness_4
|
Output:
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
post a comment