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-15]

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