How to sort a map descendingly

Hi,

I have a method that return a Map of Gross Margin <i>keys</i> and Price <i>values</i> for thecurrent sales cost.

I want to sort the values in descending order.

Here is my code

public LinkedList getCostUpMap()

{

returnnew LinkedList(myBean.getCostUpMap().entrySet());

}

Please can some one help me to solve this.

any help is highly appreciated.

Thanks and regards

Ruther

[626 byte] By [Ruthera] at [2007-11-27 2:13:14]
# 1
Have a look at this tutorial: http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
prometheuzza at 2007-7-12 2:08:33 > top of Java-index,Core,Core APIs...
# 2
Please can some one explain with a small piece of codethanks and regardsRuther
Ruthera at 2007-7-12 2:08:33 > top of Java-index,Core,Core APIs...
# 3
> Please can some one explain with a small piece of code> > thanks and regards> RutherIf you can't be bothered to read the tutorial I posted, I won't be posting any example code.
prometheuzza at 2007-7-12 2:08:33 > top of Java-index,Core,Core APIs...
# 4

If you want to order objects, you have to put them in a list.

It may be confusing to use the same name getCostUpMap for the method that returns the map and the method that returns a list of the values in the map. I would thus rename the method that returns the list as getValuesList, to be sure there is no confusion, as in:

public LinkedList getValuesList()

{

return new LinkedList(myBean.getCostUpMap().entrySet());

}

What you then have to do is to use the static methods of the class java.util.Collections to sort your list. This code would appear to do the trick:

List values = getValuesList();

Collections.sort(values); // sorts the values in ascending order

Collections.reverse(values); // reverses the order of the values

toon_macharisa at 2007-7-12 2:08:33 > top of Java-index,Core,Core APIs...