相关疑难解决方法(0)

Java LinkedHashMap获取第一个或最后一个条目

我使用过,LinkedHashMap因为重要的是键在地图中输入的顺序.

但现在我想首先获得key的值(第一个输入的条目)或最后一个.

如果有喜欢的方法first()和last()或类似的东西?

我是否需要一个迭代器才能获得第一个键入口?这就是我使用的原因LinkedHashMap!

谢谢!

java dictionary linkedhashmap

123
推荐指数
6
解决办法
11万
查看次数

如何在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万
查看次数

如何反向遍历链接哈希映射?

可能重复:
以相反的顺序迭代LinkedHashMap

如何以相反的顺序遍历链接的哈希映射?地图中是否有任何预定义方法可以做到这一点?

我正在创建它如下:

LinkedHashMap<Integer, String> map = new LinkedHashMap<Integer,String>();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
Run Code Online (Sandbox Code Playgroud)

java reverse linkedhashmap

14
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×3

linkedhashmap ×2

dictionary ×1

hashmap ×1

reverse ×1