开发者

How can I sort arraylist hasmap

开发者 https://www.devze.com 2023-03-14 19:39 出处:网络
im wondering, how can I sort my arraylist: its look like this: A开发者_开发技巧rrayList<HashMap<String, ?>> list = new ArrayList<HashMap<String, ?>>();

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, ?>>();
0

精彩评论

暂无评论...
验证码 换一张
取 消