For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2005 > no get in tree set?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author no get in tree set?
Shea Martin

2005-03-23, 3:59 pm

It appears that TreeSet has no object retrieval method. Am I overlooking
something? I probably neet to use TreeMap? I need a collection which will
be filled once, with items rarely being added or removed. But access to the
items in the list will often be random, as opposed to sequential. Is
TreeMap the best choice?

Thanks,

~S
Matt Humphrey

2005-03-23, 8:59 pm


"Shea Martin" <smartin@arcis.com> wrote in message
news:3adqd4F6a6fr9U1@individual.net...
> It appears that TreeSet has no object retrieval method. Am I overlooking
> something? I probably neet to use TreeMap? I need a collection which

will
> be filled once, with items rarely being added or removed. But access to

the
> items in the list will often be random, as opposed to sequential. Is
> TreeMap the best choice?


There's no *indexed* retrieval because it's a set, not a map. You can test
for inclusion in the set (contains(o)) or you can iterate through the items
if you like (iterator, first, last, etc). If you want indexed access, you
need some kind of Map.

Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com