Re: Get reference to object in Set
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Fri, 06 Mar 2009 06:38:26 -0800
neuneudr@xxxxxxxx wrote:
On Mar 5, 5:24 pm, Knute Johnson <nos...@xxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Patricia Shanahan wrote:I think this question has already been asked, but I have failed to workHow does .contains() find the Object? I would guess that in an
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
unordered Set it must iterate.
Isn't kinda the whole point of a set/map to use hashes
to have constant time for such operations?
True for HashSet and HashMap, but not necessarily true in general.
TreeSet, for example, has O(log n) time for contains.
Patricia
.
- Follow-Ups:
- Re: Get reference to object in Set
- From: Daniel Pitts
- Re: Get reference to object in Set
- References:
- Get reference to object in Set
- From: Patricia Shanahan
- Re: Get reference to object in Set
- From: Knute Johnson
- Re: Get reference to object in Set
- From: neuneudr
- Get reference to object in Set
- Prev by Date: Re: Get reference to object in Set
- Next by Date: Re: "getHibernateTemplate()" returns null
- Previous by thread: Re: Get reference to object in Set
- Next by thread: Re: Get reference to object in Set
- Index(es):
Relevant Pages
|