hashmap - how can i change the hash code of java class? -
my doubt is, have employee class contains 2 variable id , name follows:
public class empbean { int id=10;; string name="uday"; }
i have added object hashmap follows:
hashmap<empbean, empbean> hashmap= new hashmap<empbean, empbean>(); hashmap.put(empbean, empbean);
then:system.out.println(hashmap.get(empbean).id);
output:10;
when call get()
method of hashmap
,it calculates hashcode , apply hashing on , finds bucket , returns value.
so far fine.
if want change hash code of object before calling get() method. how can ? tried empbean.id=2000;
there no change in hashcode.
if change value in object witch in hashmap must first remove item hashmap edit value , after insert hashmap again.
Comments
Post a Comment