What is Similarities between ArrayList and HashSet ?
1680
12-Mar-2020
Updated on 23-Sep-2020
Shrikant Mishra
12-Mar-2020Here 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.