ArrayList vs HashSet

HashSet and ArrayList are among the most important classes in the Java Collection framework. Below are some differences between HashSet and ArrayList.

Implementation:

The main difference between ArrayList and HashSet is that ArrayList is the implementation of the List interface while HashSet is the implementation of the Set.

Internal implementation

ArrayList uses an array to store its elements.
HashSet uses a hashmap for its implementation.

The order of the elements

ArrayList keeps the order of the elements they are inserted from.
HashSet does not keep the order of the elements.

Duplication

ArrayList allows duplicate values.
HashSet does not allow duplicate values.

Performance
ArrayList uses an index to improve performance by calling the get(index) method to retrieve an item and remove(index) to remove an item.
HashSet is completely object-based and does not provide a get.

Null object

In ArrayList, any null element is allowed.
HashSet allows only one null value.


References: