dcsimg
HashMap related doubt
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   manikandan_chipcd
Posted On:   Friday, February 29, 2008 04:22 AM

what is the internal mechaniams of KEYS with Values mapping?

Re: HashMap related doubt

Posted By:   Robert_Lybarger  
Posted On:   Friday, February 29, 2008 07:47 PM

... but in this particular case, here's what the java api docs say, in the Map interface:

Returns true if this map contains a mapping for the specified key.
More formally, returns true if and only if this map contains a mapping for a key k such
that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

So it doesn't care *what kind* of object is put in there, it just uses the "equals" method for comparison (although I would be surprised if there is not also a quick "==" check as a performance optimization). This means that one sometimes needs to be aware of just what "equals" means to certain classes whose objects are used as keys in a map.

Re: HashMap related doubt

Posted By:   Stephen_McConnell  
Posted On:   Friday, February 29, 2008 09:53 AM

Not trying to be a smart alack, but did you know that you can look download and look at the source code for all the Java Classes.


I did that when Java was first coming out. And still do that when I need to find out how stuff works internally. I learned a lot about Java... good (and some bad) coding practices... and got ideas about implementing utility classes of my own.


It's to your credit that you want to know HOW something is implemented. It makes you a better programmer.


Stephen McConnell

About | Sitemap | Contact