• 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

Using WeakHashMap in place of HashMap .

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

In any of the projects till now i have seen , i never saw developers using WeakHashMap to store data in place of a Hashmap .

Please let me know why doesn't peole prefer weakHashMap and save memory , rather than using HashMap

Actually this is the question i want to ask
when to use WeakHashMap for storing Data ??

Thanks in advance .
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Javadocs for WeakHashMap explain when it's appropriate to use - e.g. when you're using keys of a class that overrides the equals() method you can get unexpected behaviour. And that probably covers the majority of uses of Maps. Of those cases where it would be appropriate, it often won't make much difference.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be I didn't get you what you mentioned .
But when we ever we are storing an Object in a Hash Related class , i think that we need to override equals and hashcode methods .

Could you please tell , what you were exactly refering to ??

Thanks in advance .

 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do the equals and hashcode methods have to do with when you might use a WeakHashMap over a HashMap?

The WeakHashMap javadocs Matthew mentioned have a lengthy explanation; it would appear that you have not read it so far - that's where you should start.
reply
    Bookmark Topic Watch Topic
  • New Topic