Getting keys from a SortedMap

Discussion in 'Java' started by nooneinparticular314159@yahoo.com, Mar 27, 2006.

  1. Guest

    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
     
    , Mar 27, 2006
    #1
    1. Advertisements

  2. On Sun, 26 Mar 2006 16:40:42 -0800,
    wrote:

    > 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?


    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.
     
    Owen Jacobson, Mar 27, 2006
    #2
    1. Advertisements

  3. Guest

    You're right. Thanks!

    Michael
     
    , Mar 27, 2006
    #3
  4. Owen Jacobson wrote:
    > On Sun, 26 Mar 2006 16:40:42 -0800,
    > wrote:
    >
    >> 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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Mar 27, 2006
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ike

    Re-sorting a SortedMap

    Ike, Jul 8, 2003, in forum: Java
    Replies:
    2
    Views:
    949
    Roedy Green
    Jul 8, 2003
  2. Captain Koloth

    Oddity with java.util.SortedMap

    Captain Koloth, Nov 27, 2008, in forum: Java
    Replies:
    116
    Views:
    4,349
    This account has been banned because it violated t
    Jul 30, 2012
  3. Replies:
    3
    Views:
    484
    Captain Koloth
    Dec 2, 2008
  4. Andreas Leitgeb
    Replies:
    5
    Views:
    308
    Andreas Leitgeb
    Aug 3, 2012
  5. Andreas Leitgeb
    Replies:
    5
    Views:
    313
    Andreas Leitgeb
    Aug 3, 2012
  6. Andreas Leitgeb
    Replies:
    2
    Views:
    197
    markspace
    Aug 3, 2012
  7. Andreas Leitgeb
    Replies:
    2
    Views:
    220
    markspace
    Aug 4, 2012
  8. Andreas Leitgeb
    Replies:
    2
    Views:
    233
    markspace
    Aug 4, 2012
Loading...