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

Related Posts:

  • Selenium Interview Questions and Answers I have attended some interviews during my career. I am sharing with you questions i was asked in the interviews. Hope these questions are helpful to the readers.    A Java Program to retrieve the data fro… Read More
  • Variables and Methods Variables: Variable is a name given to a memory location in which, we can store some value which can be used in a program. Variable Declaration: It is process of specifying what type of data to be stored into the memory … Read More
  • Type Casting Type Casting: The process of converting value of one Datatype to another Datatype. Two ways of Casting: Widening:  Converting a smaller datatype to higher datatype is called widening. byte-> short -> char … Read More
  • Why Webdriver driver = new FirefoxDriver();        WebDriver driver =  new FirefoxDriver();                   (vs)        FirefoxDriver driver =  new Firef… Read More
  • Data Types in Java Based on the type of data stored, data types are classifying as 3 types in Java. Primitive Datatype (Fundamental Datatype): Derived Datatype User Defined Datatype Primitive Datatype (Fundamental Datatype):  The da… Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

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