【发布时间】:2012-05-22 16:38:01
【问题描述】:
我尝试了几个小时,但没有找到任何最佳方法来实现反向哈希图的迭代,这就是我拥有的哈希图。
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 }));
}
我也看过 TreeMap 的例子,
Map<Integer, List<String>> sortedMap = new TreeMap<Integer, List<String>>(map);
但是树形图也以升序排列,我想要的是降序排列。
【问题讨论】:
-
HashMap 没有顺序,所以也没有逆序。