Now I'm trying to figure out how to build Hashtable.
The most interesting is how are objects added to Hashtable?
I read in a book that:
in the first step: Calculated object hashCode().
Next, we determine the position of the object Hashtable: obj.hashCode() % Hashtable.length.
For example, add more elements to Hashtable:
Hashtable<String, String> hm=new Hashtable<String, String>(100);
hm.put("Lee","Lee");
hm.put("lee","lee");
hm.put("eel","eel");
Define the bucket in which the object is placed:
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 should 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 do we see as a result?
System.out.println(hm);
{Lee=Lee, lee=lee, eel=eel}
Please tell me where I made a mistake?