Get reference to object in Set
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Thu, 05 Mar 2009 08:04:17 -0800
I think this question has already been asked, but I have failed to work
out a good search term to find the previous discussion.
Suppose I have a Set<MyType> mySet and a MyType myObject.
mySet.contains(myObject) is true. I need a reference to the equal object
that is already in mySet.
Currently, I do this by maintaining a Map<MyType,MyType>. When the get
call returns null I do a myMap.put(myObject, myObject), so that future
get calls with equal objects will return the actual reference.
Is there a better way to handle this? Any way to make a Set return a
reference to the object it contains?
Patricia
.
- Follow-Ups:
- Re: Get reference to object in Set
- From: Roedy Green
- Re: Get reference to object in Set
- From: Thomas ***in
- Re: Get reference to object in Set
- From: Daniel Pitts
- Re: Get reference to object in Set
- From: Knute Johnson
- Re: Get reference to object in Set
- From: Tom Anderson
- Re: Get reference to object in Set
- From: Fatal
- Re: Get reference to object in Set
- Prev by Date: Re: JAVA GUI QUESTION...
- Next by Date: Re: Get reference to object in Set
- Previous by thread: JAVA GUI QUESTION...
- Next by thread: Re: Get reference to object in Set
- Index(es):