How to get element position from Java Map

后端 未结 13 1490
执念已碎
执念已碎 2021-01-07 20:11

I have this Java Map:

Can you tell me how I can get the 6-th element of the Map?

private static final Map cache = new HashMap<         


        
13条回答
  •  爱一瞬间的悲伤
    2021-01-07 20:39

    The HashMap has no defined ordering of keys.It's Unordered.

    You can use LinkedHashMap which will store your keys in order of insertion.You can retrieve them by calling keySet().

提交回复
热议问题