This class provides a skeletal implementation of the List interface in order to reduce the effort required to implement this interface in combination with a “random access” data store (such as an array). Abstract List should be used instead of this class for sequential access data (such as a linked list).
public abstract class AbstractList<E> extends AbstractCollection<E>
implements List<E>
Method | Description |
---|---|
add(E e) | Appends the specified element to the end of this list (optional operation). |
add(int index, E element) | Inserts the specified element at the specified position in this list (optional operation). |
addAll(int index, Collection<? extends E> c) | Inserts all of the elements in the specified collection into this list at the specified position (optional operation). |
clear() | Removes all of the elements from this list (optional operation). |
equals(Object o) | Compares the specified object with this list for equality. |
get(int index) | Returns the element at the specified position in this list. |
hashCode() | Returns the hash code value for this list. |
indexOf(Object o) | Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. |
iterator() | Returns an iterator over the elements in this list in proper sequence. |
lastIndexOf(Object o) | Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. |
listIterator() | Returns a list iterator over the elements in this list (in proper sequence). |
listIterator(int index) | Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. |
remove(int index) | Removes the element at the specified position in this list (optional operation). |
removeRange(int fromIndex, int toIndex) | Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. |
set(int index, E element) | Replaces the element at the specified position in this list with the specified element (optional operation). |
subList(int fromIndex, int toIndex) | Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. |
import java.util.LinkedList;
import java.util.AbstractList;
public class Demo {
public static void main(String[] args) {
AbstractList<Integer> myList = new LinkedList<Integer>();
myList.add(50);
myList.add(100);
myList.add(150);
myList.add(200);
myList.add(250);
myList.add(300);
myList.add(350);
myList.add(400);
System.out.println("Elements in the AbstractList class = " + myList);
myList.remove(3);
// Print the final list
System.out.println("Final AbstractList: " + myList);
// getting the index of last occurrence
// using lastIndexOf() method
int lastindex = myList.lastIndexOf("A");
// printing the Index
System.out.println("Last index of A : "
+ lastindex);
}
}
Elements in the AbstractList class = [50, 100, 150, 200, 250, 300, 350, 400]
Final AbstractList: [50, 100, 150, 250, 300, 350, 400]
Last index of A : -1
Note: also read about the File class 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…