What is the difference between "ArrayList" and "HashSet" in Java?
1912
12-Mar-2020
Updated on 23-Sep-2020
Shrikant Mishra
12-Mar-20201) The first and most important difference between ArrayList and HashSet is that ArrayList implements List interface while HashSet implements Set interface in Java.
2) Any other difference between ArrayList and HashSet is that ArrayListallow duplicates while HashSet doesn't allow duplicates. This is the side effect of the first difference and property of implementing the List and Set interface.
3) The third difference between ArrayList and HashSet is that ArrayList is an ordered collection and maintains the insertion order of elements while HashSet is an unordered collection and doesn't maintain any order.
4) The fourth difference between ArrayList and HashSet is that ArrayList is backed by an Array while HashSet is backed by a HashMap instance.
5) The fifth difference between HashSet and ArrayList is that its index-based you can retrieve an object by calling get(index) or remove objects by calling remove(index) while HashSet is completely objective-based. HashSet also doesn't provide the get() method.
That's all about the difference between ArrayList and HashSet.