The below Java example shows how to create a collection object which extends ArrayList. The below program does two things 1) Adds in a few string objects and one in between 2) Finds the index of a particular string object in the collection object.
import java.util.*;
public class Reading<E> extends ArrayList<E> {
public static void main(String[] args) {
Reading<String> reading = new Reading();
reading.add("Hello USA!");
reading.add("Roof Top");
reading.add("Fish");
reading.add(2, "Hello Again");
ListIterator<String> books = reading.listIterator(0);
while(books.hasNext())
System.out.println(books.next());
System.out.println(reading.lastIndexOf("Fish"));
}
}
The outcome is as follows:-
Hello USA! Roof Top Hello Again Fish 3