Why LinkedList
and ArrayList
extends AbstractList
in Java?
Abstract classes are used when we want to specify a common beh
subList(int,int)
method is not overriden by both ArrayList
and LinkedList
, and for this AbstractList
provides a common implementation
From Java source
public List subList(int fromIndex, int toIndex) {
return (this instanceof RandomAccess ?
new RandomAccessSubList(this, fromIndex, toIndex) :
new SubList(this, fromIndex, toIndex));
}
In addition there are other methods which are not overriden like toString()
and iterator()