|
|||||||
| Java (NOT JavaScript!) For discussion of the Java programming language as it applies to the Web ( Not JavaScript ). |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting a Map
Hi,
How can I sort a map by value, the following code sort it in a list but the map remain unsorted: Code:
Set entries = map.entrySet();
List entryList = new ArrayList(entries);
Collections.sort(entryList, new Comparator() {
public int compare(Object o1, Object o2) {
MapEntry me1 = (MapEntry)o1;
MapEntry me2 = (MapEntry)o2;
return ((Comparable)me2.getValue()).compareTo(me1.getValue());
}
});
Hind |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|