The moose likes Java in General and the fly likes HashMap keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap keys" Watch "HashMap keys" New topic

HashMap keys

Allen Thomas

Joined: Jul 02, 2002
Posts: 29
I read somewhere that String objects oppose to Integer Objects are far better to use as the key for HashMap because strings are immutable. On the other hand, a recent post by someone on here, said that Integer Objects are better than String Objects to use as keys because they are efficient when searching.
Could anyone explain to me which is better to use?
Thank you in advance.
Vin Kris
Ranch Hand

Joined: Jun 17, 2002
Posts: 154
If *immutable* is the reason, then even Integer objects are immutable. Can you post the link?
Allen Thomas

Joined: Jul 02, 2002
Posts: 29
Here is the link that says to use Strings as the keys: (Slide 15)
www.cis.upenn.edu/~matuszek/cit594-2002/ Slides/using-maps.ppt
Here is the link that says Integers are better performing
saloon.javaranch.com/34/002109.html posted by ranch hand Steve Deadsea, but I think he is talking about HashTable. Same concept?
I agree. Here's the link: http://aspose.com/file-tools
subject: HashMap keys
Similar Threads
Check one of the property of objects contains the given value
HashMap bean with generic type parameters
is it alright to use the string member's hashcode as hashcode for the Object ?
why they use hashCode() method in equals() method
convert "forty five" to "45"