Re-sorting a SortedMap

Discussion in 'Java' started by Ike, Jul 8, 2003.

  1. Ike

    Ike Guest

    If I have a sorted map, of objects which have as one of the object fields, a
    String, and I want to iterate through my sorted map based on the alphabetic
    order of this String field of the member objects of the SortedMap, how can I
    do this efficiently?

    Thanks, Ike
     
    Ike, Jul 8, 2003
    #1
    1. Advertising

  2. Ike

    VisionSet Guest

    "Ike" <> wrote in message
    news:SAyOa.89360$...
    > If I have a sorted map, of objects which have as one of the object fields,

    a
    > String, and I want to iterate through my sorted map based on the

    alphabetic
    > order of this String field of the member objects of the SortedMap, how can

    I
    > do this efficiently?
    >
    > Thanks, Ike


    SortedMap myNewSortedMap = new TreeMap(Comparator c);
    myNewSortedMap.putAll(oldSortedMap);

    write a comparator class with compare methods that operate on the fields you
    are interested in.

    --
    Mike W
     
    VisionSet, Jul 8, 2003
    #2
    1. Advertising

  3. Ike

    Roedy Green Guest

    On Tue, 08 Jul 2003 12:14:42 GMT, "Ike" <> wrote or
    quoted :

    >If I have a sorted map, of objects which have as one of the object fields, a
    >String, and I want to iterate through my sorted map based on the alphabetic
    >order of this String field of the member objects of the SortedMap, how can I
    >do this efficiently?


    Export to an array and sort that or export and create a new SortedMap
    if you want to maintain the sorted order.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 8, 2003
    #3
    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. Replies:
    3
    Views:
    777
    Thomas Hawtin
    Mar 27, 2006
  2. Captain Koloth

    Oddity with java.util.SortedMap

    Captain Koloth, Nov 27, 2008, in forum: Java
    Replies:
    116
    Views:
    3,774
    This account has been banned because it violated t
    Jul 30, 2012
  3. Replies:
    3
    Views:
    395
    Captain Koloth
    Dec 2, 2008
  4. Andreas Leitgeb
    Replies:
    5
    Views:
    229
    Andreas Leitgeb
    Aug 3, 2012
  5. Andreas Leitgeb
    Replies:
    5
    Views:
    205
    Andreas Leitgeb
    Aug 3, 2012
Loading...

Share This Page