Monday, December 31, 2018

Difference between Arraylist and HashMap?
  • ArrayList implements List Interface while HashMap is an implementation of Map interface.
  • Memory consumption is high in HashMap compared to the ArrayList.
  • ArrayList maintains the insertion order while HashMap doesn't maintain any order. ArrayList stores the elements only as value and maintain internally the indexing for every element. While HashMap stores elements with key and value pair, i.e. two objects. So HashMap takes more memory comparatively.
  • ArrayList allows duplicate elements but HashMap doesn't allow duplicate keys (It does allow duplicate values)
  • In ArrayList, an element can be fetched easily by specifying the index of it. But in HashMap, the elements is fetched by its corresponding key. It means that the key must be remembered always.
  •  In ArrayList, any number of null elements can be stored. While in HashMap, only one null key is allowed, but the values can be of any number.
ARRAYLISTHASHMAP
The java ArrayList implements List InterfaceThe java HashMap is implements Map interface
ArrayList always maintain insertion order of the elementsHashMap does not maintain the insertion order
ArrayList only stores value or elementHashMap stores key and value pairs
ArrayList can contain duplicate elementsHashMap does not contain duplicate keys but contain duplicate values.
We can have any numbers of null elements in ArrayListWe can have only one null key and any number of null values in HashMap
ArrayList get() method always gives an O(1) performanceHashMap get()method can be O(1) in the best case and O(n) in the worst case

0 comments:

Post a Comment

selenium-repo by venu

Blog helps to a student or IT employee to develop or improve skills in Software Testing.
For Online Classes Email us: gadiparthi122@mail.com

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts