• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Key in the HashMap.

 
pawan chopra
Ranch Hand
Posts: 415
jQuery Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have hashmap..and keys are object to put in map..i need a new object ecah time I need to put a value. Is there any way i can resue the same object for different key?
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Can you clarify (greatly) just what you're trying to do?
2) Is this truly a Swing or other GUI-related question? And if so, how?

Much luck
 
pawan chopra
Ranch Hand
Posts: 415
jQuery Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Sorry...posted in wrong forum....Can any one please move it to Java general forum.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Sorry...posted in wrong forum....Can any one please move it to Java general forum.

I think that this is the minor issue regarding your question and that the greater problem is that the question is still not comprehensible. Don't you want to fix this?
 
pawan chopra
Ranch Hand
Posts: 415
jQuery Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I have 10000 objects and I need to put hem in to a map and use them as Key. It may be 10 millions. My question is there any way I can save myself from creating so many objects ....I am worried about the performance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use an object as a key in a HashMap, the object's state must not change as long as it is used as a key. If the object's state changes in a way so that the hash code of the object changes, then the HashMap will get confused and won't work properly anymore. It's safest to use only immutable objects as keys in a HashMap.

So, you cannot use a mutable object like this, for example:

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic