Iterate to find a Map entry at an index?

前端 未结 4 1829
小鲜肉
小鲜肉 2020-12-20 13:35

I have a LinkedHashMap. I want to get the Foo at index N. Is there a better way of doing this besides iterating until I find it?:

int target = N;
int index =         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 13:53

    List> randAccess = new ArrayList>(foos.entrySet());
    

    Then for index N with O(1) access...

    randAccess.get(N)
    

提交回复
热议问题