Possible Duplicate:
How does Java hashmap work?
Can someone explain to me how HashSets in java work and why they are faster than using ArrayLists?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First,
HashSet, unlikeArrayListis a Set: It cannot contain duplicates whileArrayListcan – so they are built for different purposes. It also does not guarantee ordering – again, unlike a list.Second – a
HashSetis built on the hash table data structure, that allowsO(1)seek time for an element.Note that many times, a
HashSetis slower then anArrayList– if you want to iterate on elements for example – usually doing it in anArrayListwill be faster then in aHashSet[because of bad cache performance of hash, among other reasons]