db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raphael.X.Mankin%GSK...@gsk.com
Subject Re: SortedMap in reverse order
Date Mon, 19 Jul 2004 08:05:21 GMT
Hvae you looked at java.util.Collections? See the methods reverse(), which
reverses (moodifes) the collection, and reverseOrder(), which just provides
a convenient comparator.


Try something like

            // Create a TreeMap that sorts in the reverse order
             SortedMap sortedMap = new
TreeMap(java.util.Collections.reverseOrder());
            // Now add all the data to it
             sortedMap.putAll(ht);
             Iterator iter = sortedMap.keySet().iterator();
             while (iter.hasNext())
             {
                         String key = (String)iter.next();
                         out.println(sortedMap.get(key));

             }//end while



|---------+----------------------------->
|         |           "Veronique        |
|         |           Couderc"          |
|         |           <veroniquec@sensor|
|         |           ynet.co.uk>       |
|         |                             |
|         |                             |
|         |           16-Jul-2004 17:25 |
|         |           Please respond to |
|         |           "Apache Torque    |
|         |           Users List"       |
|         |           <torque-user@db.ap|
|         |           ache.org>         |
|         |                             |
|---------+----------------------------->
  >-------------------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                                  |
  |                                                                                      
                                  |
  |                                                                                      
                                  |
  |       To:      "Apache Torque" <torque-user@db.apache.org>                     
                                        |
  |                                                                                      
                                  |
  |       cc:                                                                            
                                  |
  |       Subject: SortedMap in reverse order                                            
                                  |
  >-------------------------------------------------------------------------------------------------------------------------|




Hi,

Do you know how to use SortedMap in a descending order?


This prints the elements in ascending order:

             SortedMap sortedMap = new TreeMap();
             sortedMap.putAll(ht);
             Iterator iter = sortedMap.keySet().iterator();
             while (iter.hasNext())
             {
                         String key = (String)iter.next();
                         out.println(sortedMap.get(key));

             }//end while


I found this on the net but can't make it work:

Creates a reversed version of this map.
Must be <code>O(n)</code>, where <code>n</code> is the number of
elements in this collection.
@return  A map with the elements in reverse order.
public abstract SortedMap reversed();

Many thanks
vero




--
Regards

Veronique Couderc
SensoryNet Ltd, London

t. 0845 226 3012
f. 0845 226 8512


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org









---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message