• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

working of map?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

can anyone please explain how the 'map' works?? ofcourse we explicitly do not call equals and hashcode methods, but i do not know when are those methods called and how are the data stored in the map?? i think knowing these details could help me get the concepts..
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/* This is the simple concept of equal and hash code. I prefer if you can read the bucket example give in
K&B. When you put a key~value pair. Hash code value of key is find out and it is kept in the bucket and value is
associated with it.
Now when you try to get out the value using key. for eg : m.get(k2)
here it first find out the hashcode of k2, then it goes to specific bucket and pull out
all the keys related to that bucket.compare each key with k2, first match and value is return to you.

Also do remember the hashcode and equals contract.
if two objects are equal, means they must belong to same bucket. that means their hash code must be equal.
but if two object have equal hashcodes, they may or may not be equal.*/
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by venkatesh badrinathan:

can anyone please explain how the 'map' works?? ofcourse we explicitly do not call equals and hashcode methods, but i do not know when are those methods called and how are the data stored in the map?? i think knowing these details could help me get the concepts..



This is an example from K&B. It is explained there. And darling! a very few in this world can make you understand the core JAVA better than Kathy & Bert do. So stick there. I repeat, stick there. Go through the chapter after and after until you grasp it. I went through that chapter thrice and still going through.
-Best of luck............................
 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had exactly the same problem..

Got somepart of it ..but still not crystal clear..

Any way.. Check this link out.

I assure you it 'll definetly help...

https://coderanch.com/t/268571/java-programmer-SCJP/certification/equals-hashCode


https://coderanch.com/t/268751/java-programmer-SCJP/certification/hashCode-equals
 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nabila
 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have seen programs where
put(arg1,arg2)
arg1 is used as a key and arg2 as value and, vise-versa. is it possible to use
arg2 as key and arg1 as value??? if so, while we retrieve the value from buckets will not there be any prob???
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of problem do you think it 'll come across....?
reply
    Bookmark Topic Watch Topic
  • New Topic