相关疑难解决方法(0)

如何在Java中以相反的顺序迭代hashmap

我试了几个小时,但没有找到任何最好的方法来以相反的顺序实现hashmap的迭代,这是我的hashmap.

      Map<Integer, List<String>> map = new HashMap<Integer, List<String>>();

             for(Integer key : map.keySet()) {
                List<String> value = map.get(key);
                List<Map<String,?>> security = new LinkedList<Map<String,?>>();  
                for(int ixy = 0; ixy < value.size()-1; ixy++){
                    security.add(createItem(value.get(ixy), value.get(ixy+1))); 
                }
                adapter.addSection(Integer.toString(key), new SimpleAdapter(getApplicationContext(), security, R.layout.list_complex, new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));  
            }
Run Code Online (Sandbox Code Playgroud)

我也见过TreeMap的例子,

             Map<Integer, List<String>> sortedMap = new TreeMap<Integer, List<String>>(map);
Run Code Online (Sandbox Code Playgroud)

但是树形图也按升序给出,我想要的是降序.

java hashmap

18
推荐指数
5
解决办法
6万
查看次数

标签 统计

hashmap ×1

java ×1