Why LinkedList and arraylist extends AbstractList in java?

后端 未结 4 1357
一个人的身影
一个人的身影 2021-02-13 18:41

Why LinkedList and ArrayList extends AbstractList in Java?

Abstract classes are used when we want to specify a common beh

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 19:13

    You can get Answer from Here,,, AbstractList

    This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array). For sequential access data (such as a linked list), AbstractSequentialList should be used in preference to this Class. To implement an unmodifiable List, the programmer needs only to extend this class and provide implementations for the get(int index) and size() methods.

    To implement a modifiable List, the programmer must additionally override the set(int index, Object element) method (which otherwise throws an UnsupportedOperationException. If the List is variable-size the programmer must additionally override the add(int index, Object element) and remove(int index) methods.

    The programmer should generally provide a void (no argument) and Collection constructor, as per the recommendation in the Collection interface specification.

    Unlike the other abstract Collection implementations, the programmer does not have to provide an Iterator implementation; the iterator and listIterator are implemented by this class, on top the "random access" methods: get(int index), set(int index, Object element), set(int index, Object element), add(int index, Object element) and remove(int index).

    The documentation for each non-abstract methods in this class describes its implementation in detail. Each of these methods may be overridden if the Collection being implemented admits a more efficient implementation.

提交回复
热议问题