Wednesday, 18 November 2015

ArrayList vs HashMap in Java

Implementation of java.util.List Interface.
Implementation of java.util.Map interface.

It used to store the object.
It is used to store the object in key-value pair.
Where key and value are different objects.

Methods to implement
No method is required to implement.

However contains() method uses the equals() method to check the existence of the object.
For HashMap, class which is used as key must implements equals() and hashCode() method correctly.

Better hashcode() implementation will lead to better performance.

ArrayList maintain order of object.
HashMap doesn't provide any order guarantee.

ArrayList allows duplicates
HashMap doesn't allow duplicates key, though it allows duplicate values.

Size increase 50% after resizing.
Size increase 100%. Load factor plays the vital role to resize the HashMap.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...