naved momin wrote:
if you look at the out put carefully and code you will find that value of this.name changes whenever hashmap put's or get's the value thats the only thing left here i m not getting
can any one explain ?
Hi,
follow this link :
http://www.docjar.com/html/api/java/util/Hashtable.java.html
This code is an implementation of HashTable in
Java.
Look at these lines, this is a way Hastable.put() is implemented:
Do you see it ?
All your objects have the same hash value.
So HashTable stores them in the same bucket ( tab[ (hash & 0x7FFFFFFF) % tab.length ] ).
Buckets are implemented as simple arrays.
HashTable loops through all elements of this bucked (array) and for each table element calls it's element.equals( key ) method.