Now, I'm trying to understand how to construct the Hashtable
.
The most interesting - as objects are added to the Hashtable
?
I have read in a book that:
at first step:
Calculated hashCode()
object.
Next, we determine the position of this object in the Hashtable
: obj.hashCode() % Hashtable.length
.
For example, add more elements to the Hashtable
:
Hashtable<String, String> hm=new Hashtable<String, String>(100);
hm.put("Lee","Lee");
hm.put("lee","lee");
hm.put("eel","eel");
Define a bucket into which is placed the object:
System.out.println("Lee".hashCode() % 100);
System.out.println("lee".hashCode() % 100);
System.out.println("eel".hashCode() % 100);
If I understand the algorithm, the objects must be placed in the table as follows:
eel /*because,"eel".hashCode() % 100=0*/,
lee /*because, "lee".hashCode() % 100=20*/,
Lee /*because, "Lee".hashCode() % 100=68*/
but what we see as a result?
System.out.println(hm);
{Lee=Lee, lee=lee, eel=eel}
Please, tell me, where did I go wrong?