What is the difference b/w 2d array and hashmap?Where we have to use this?Explain ?
Thanks in advance

Questions by nandhu431

Showing Answers 1 - 3 of 3 Answers

Two dimension array can store only homogenous elements i.e only one data type. If we try to store the heterogeneous elements into 2D array then we will get compile time error.
In HashMap we can store both homogenous elements and heterogeneous elements. Build in functions are there to sort and duplicates are allowed in values but not in keys i.e HashMap is having some extra predefined features are there to use but 2D array is not having all these and if we need then we need to write customized code. HashMap is stored as key and value pairs but in 2D array we can store only values in 2-Dimension.

  Was this answer useful?  Yes


  • Dec 26th, 2014

2d array is fixed in size ,hashmap size is not fixed
2d array rep.set of elements a[][],hashmap is (key,value) pair
in 2d searching is slow ,it visits each n every element ,searchng is based on key so fast
2d array can be used in printing elements.
hashmap in realtime projects to retrive particular employee salary using key.

  Was this answer useful?  Yes


  • Apr 9th, 2015

Array is fixed size and it has doesnt fixed data structure so there is no ready-mate methods for operating we write the explicitly write code burden for the programmer.
Advantage: performance wise is arrays are best.
If we want to store the key - value pairs in a single entity we go for HashMap.
In hashmap is only one null key,but values must be null allowed .
Duplicates are not allowed and insertion order is not preserved based on hash table.the hashmap data structure is hash table.It is not a thread safe.
Use:hash map implements the hashtable we dont want to any duplicates in insertion the we go for hash map.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions