What is HashMap | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is HashMap

17th Sep 2016, 10:01 PM
violet
3 Answers
+ 3
In a Hashtable, instead of accessing elements with an index number (like in arrays for example), you access them with their key (which can be a number, a string, etc.). For example, here we create a new Hashtable dictionary, insert the key/value pair "blanc"/"white", and display the item with key "blanc": Hashtable dictionary = new Hashtable(); dictionary.put("blanc", "white"); System.out.println(dictionary.get("blanc")); A HashMap is almost like a Hashtable, the only differences being that it accepts null as value or key, and it is not thread-safe.
17th Sep 2016, 10:37 PM
Zen
Zen - avatar
+ 2
just like an ArrayList but instead of indexing elements using Integers , You can use e.g Strings or other types ... e.g. HashMap hm=new HashMap<String,String>();
17th Sep 2016, 10:19 PM
Ahmad Samy
Ahmad Samy - avatar
0
Hashtable? What's that?
17th Sep 2016, 11:18 PM
violet