如何基于索引不是关键得到LinkedHashMap的价值?索引、关键、价值、不是

2023-09-12 23:56:45 作者:揉奶師

LinkedHashMap<String, List<String>> hMap;

我想获得名单,其中,字符串&GT; 按位置不是关键

我不希望使用迭代。

有没有其他办法以指数值?

Is there any other way to get Value based on index ?

推荐答案

您不能得到地图基于指数的值,地图只是不这样的。一种解决方法是创建从你的价值一个新的列表,并获得基于索引的价值。

You can't get the value of the Map based on index, Maps just don't work that way. A workaround would be to create a new list from your values and get the value based on index.

LinkedHashMap<String, List<String>> hMap;
List<List<String>> l = new ArrayList<List<String>>(hMap.values());
l.get(0);