Hello. I am storing some data in a TreeMap, and I need to get a subset
of that data. Conveniently, I can get exactly the data I want using
tailmap, which returns a SortedMap. Not so conveniently, I need to get
my objects out of the SortedMap, which seems to require knowing what
the keys are that are used to index the SortedMap. I don't necessarily
know what these keys are. Nothing that I've tried has given me the
actual keys. Is there a way to get the keys out of a SortedMap?
Alternately, is there a way to iterate over the elements in a
SortedMap? I don't think that I can get the first or last element and
remove it, because that will destroy the object backing the map.
Thanks,
Michael
> Hello. I am storing some data in a TreeMap, and I need to get a subset
> of that data. Conveniently, I can get exactly the data I want using
[quoted text clipped - 5 lines]
> Alternately, is there a way to iterate over the elements in a
> SortedMap?
Something wrong with using keySet (), which returns a set of all keys on
the map, or entrySet (), which returns a set of all key->value mappings on
the map? They're inherited from Map to SortedMap.
nooneinparticular314159@yahoo.com - 27 Mar 2006 04:24 GMT
You're right. Thanks!
Michael
Thomas Hawtin - 27 Mar 2006 17:10 GMT
>> tailmap, which returns a SortedMap. Not so conveniently, I need to get
>> my objects out of the SortedMap, which seems to require knowing what
>> the keys are that are used to index the SortedMap. I don't necessarily
> Something wrong with using keySet (), which returns a set of all keys on
> the map, or entrySet (), which returns a set of all key->value mappings on
> the map? They're inherited from Map to SortedMap.
Or if you just want the values, use Map.values.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/