Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ArrayList have "implements List"? [duplicate]

In the Collection Framework we have the interface List and the class AbstractList:

AbstractList implements List 

And ArrayList extends AbstractList and

implements List 

My question: why does ArrayList have the implements List clause?

If ArrayList extends AbstractList and AbstractList implements List, can't we say, that ArrayList implement List?

like image 932
user471011 Avatar asked Dec 08 '10 12:12

user471011


People also ask

Does ArrayList contain duplicates?

ArrayList allows duplicate values in its collection. On other hand duplicate elements are not allowed in Hashset. HashSet is completely based on object also it doesn't provide get() method.

Why list allow duplicate values in Java?

List allows duplicates while Set doesn't allow duplicate elements . All the elements of a Set should be unique if you try to insert the duplicate element in Set it would replace the existing value. List permits any number of null values in its collection while Set permits only one null value in its collection.

Does ArrayList accept duplicates Java?

ArrayList allows duplicate values while HashSet doesn't allow duplicates values. Ordering : ArrayList maintains the order of the object in which they are inserted while HashSet is an unordered collection and doesn't maintain any order.


1 Answers

Yes. It could've been omitted. But thus it is immediately visible that it is a List. Otherwise an extra click through the code / documentation would be required. I think that's the reason - clarity.

And to add what Joeri Hendrickx commented - it is for the purpose of showing that ArrayList implements List. AbstractList in the whole picture is just for convenience and to reduce code duplication between List implementations.

like image 135
Bozho Avatar answered Oct 19 '22 21:10

Bozho