Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Getting keys from a SortedMap

Thread view: 
nooneinparticular314159@yahoo.com - 27 Mar 2006 01:40 GMT
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
Owen Jacobson - 27 Mar 2006 02:10 GMT
> 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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.