Difference between arraylist and hashmap
Here we are going to learn difference between arraylist and hashmap or arraylist vs hashmap with example.
ArrayList vs HashMap differ based on following parameters:
ArrayList stores only the value of the element.
HashMap applies different mechanism as it stores value of the element along with a unique keyassociated to the stored value.
2. Memory requirement
As ArrayList only stores the value of the element so it requires less memory space in comparision to HashMap.
On other hand HashMap needs to store a unique key for each value so memory requirement increases.
ArrayList implements List interface.
HashMap implements Map interface.
4. Order maintainence
ArrayList ensures that the insertion order is maintained.
HashMap doesn’t guarantee of maintaining insertion order (if you care about order, use LinkedHashMap).
*In case where insertion order is maintained we get the elements returned in same order in which they were inserted while retrieving them.
5. Null value
Any number of null values can be stored in ArrayList.
Only one null key is allowed in HashMap. But you can store any number of null values.
6. Duplicate value
ArrayList accepts duplicate values while storing.
HashMap doesn’t accept duplicate Key. But duplicate values are allowed.
7. Retrieve element
In ArrayList elements can be retrieved specifying index of the element.
In HashMap elements can be retrieved by specifying its Key.
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Technology geek, loves to write and share knowledge with the world. Having 9+ years of IT experience. B.Tech in Computer Science & Engineering
Page Views :
Published Date :