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. Advertising

  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. Advertising

  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. Advertising

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. Andreas Leitgeb
    Replies:
    5
    Views:
    195
    Andreas Leitgeb
    Aug 3, 2012
  2. Andreas Leitgeb
    Replies:
    5
    Views:
    181
    Andreas Leitgeb
    Aug 3, 2012
  3. Andreas Leitgeb
    Replies:
    2
    Views:
    114
    markspace
    Aug 3, 2012
  4. Andreas Leitgeb
    Replies:
    2
    Views:
    134
    markspace
    Aug 4, 2012
  5. Andreas Leitgeb
    Replies:
    2
    Views:
    141
    markspace
    Aug 4, 2012
Loading...

Share This Page