Re-sorting a SortedMap

I

Ike

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
 
V

VisionSet

Ike said:
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.
 
R

Roedy Green

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top