2

im wondering, how can I sort my arraylist: its look like this:

ArrayList<HashMap<String, ?>> list = new ArrayList<HashMap<String, ?>>();
temp.put("Position", count);
list.add(temp);

I would sort by Position key.

Dawid Sajdak
  • 3,064
  • 2
  • 23
  • 37

2 Answers2

3

please try it.

Comparator comparator = Collections.reverseOrder();
Collections.sort(list,comparator);

And also check it.

Sort a Map<Key, Value> by values (Java)

Community
  • 1
  • 1
Nikhil
  • 16,194
  • 20
  • 64
  • 81
1

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, ?>>();
Fabian Steeg
  • 44,988
  • 7
  • 85
  • 112