Have been going through the Java for sometime now and got stuck at yet another question. HashMaps or HashTables.
have gone through the basics..how a hash table is implemented..like calculating a hash value..storing data at the hash value(or probably hashvalue % maxArray) index..linear probing and chaining for collisions. Now to further, if somebody could please help with below:
Basic examples show storing Strings like "Jhon", "Lisa" , "Sam" etc in an array then going through collisions and converting the array to Linked list to store the names which is all good to understand and super fine.
- But Hashtables store Key,Value pair. So how it is achieved?
- The key,value pair examples show "Telephone Directory" example, but they do not show how they are stored in Arrays or linked list. It is just Map.put(k,v) and Map.get(k). Linked list store "One Data" and "Pointer".. so how can we store both Keys and Values in Linked list( A picture might help in understanding)
- A bit more practical example for Hash Table than map.put("Rocket", 01111111111).
HashMap
or check these links: coding-geek.com/how-does-a-hashmap-work-in-java, howtodoinjava.com/core-java/collections/…, geeksforgeeks.org/internal-working-of-hashmap-java – IvanHashMap
operates withEntry
objects which store key and value. It is developer who must overridehashCode()
andequals()
to be able to use objects of his custom class as keys inHashMap
. – Ivan