• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

HashMap keys  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Allen
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If *immutable* is the reason, then even Integer objects are immutable. Can you post the link?
 
Allen Thomas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!