Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re-sorting a SortedMap

Reply
Thread Tools

Re-sorting a SortedMap

 
 
Ike
Guest
Posts: n/a
 
      07-08-2003
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


 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      07-08-2003
"Ike" <(E-Mail Removed)> wrote in message
news:SAyOa.89360$(E-Mail Removed) thlink.net...
> 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


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-08-2003
On Tue, 08 Jul 2003 12:14:42 GMT, "Ike" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SortedMap: getting value for largest key less or equal a given Andreas Leitgeb Java 5 08-03-2012 06:54 PM
SortedMap: getting value for largest key less or equal a givenvalue... Andreas Leitgeb Java 5 08-03-2012 12:55 AM
Oddity with java.util.SortedMap Captain Koloth Java 116 07-30-2012 02:33 AM
Against Twisted and Oddity with java.util.SortedMap antitwisted@gmail.com Java 3 12-02-2008 01:14 AM
Getting keys from a SortedMap nooneinparticular314159@yahoo.com Java 3 03-27-2006 04:10 PM



Advertisments