How can I sort arraylist hasmap
im wondering, how can I sort my arraylist: its look like this:
A开发者_开发技巧rrayList<HashMap<String, ?>> list = new ArrayList<HashMap<String, ?>>();
temp.put("Position", count);
list.add(temp);
I would sort by Position key.
please try it.
Comparator comparator = Collections.reverseOrder();
Collections.sort(list,comparator);
And also check it.
Sort a Map<Key, Value> by values (Java)
If what you want is to sort the map entries by their keys, you can use a SortedMap
(e.g. TreeMap
):
List<SortedMap<String, ?>> list = new ArrayList<SortedMap<String, ?>>();
精彩评论