This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am not sure whether i understood what is the content of your list but if you want to sort the Items then you have to get the values using values() and then sort it as you would sort any other list. (Colections.sort())
Ulf Dittmer wrote:It is important to realize that a Map has no sort order.
The SortedMap interface, and its implementation TreeMap, disagree with you
However, these only impose an order on the keys, not on the values. There is no known implementation that sorts on the values, and the reason is clear: it basically turns your Map into a list of Map.Entry objects as far as performance goes. get() looks up values based on a key, and if the Map is sorted on the value the Map will have to check every entry until a match is found.
Of course, if you really need this, you can implement it yourself:
But would you agree that a SortedMap is a Map? And thus, some Maps do have sort order, even while others do not?
I think when you say "a Map has no sort order", it sounds to Rob and me as if you're saying no Map has sort order, when you probably mean that a Map, in general, cannot be assumed to have sort order. Unless of course one has more specific knowledge about the type of Map they're dealing with.