What is Similarities between ArrayList and HashSet ?

Posted by  ShriKant Mishra
 64  View(s)
Ratings:
Rate this:
  1. What is Similarities between ArrayList and HashSet ?

    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