What is Similarities between ArrayList and HashSet ?

Last updated:9/23/2020 2:09:13 PM

1 Answers

Shrikant Mishra
Shrikant Mishra

Here are a couple of similarities between ArrayList and HashSet in Java:

1) Both ArrayList and HashSet have not synchronized collection classes and not meant to be used in multi-threading and concurrent environments. You can make ArrayList and HashSet synchronized by using Collections.synchroinzedCollection() just like we make ArrayList and HashSet read-only another day.

2) The ArrayList and the HashSet both can be traversed using Iterator. This is, in fact, a preferred way if you want to perform an operation on all elements. 

3) An iterator of ArrayList and HashSet both are fail-fast, i.e. they will throw ConcurrentModificationException if ArrayList or HashSet is modified structurally once Iterator has been created.

Answer