Why doesn't java.util.Set have get(int index)?

前端 未结 18 1372
长情又很酷
长情又很酷 2020-11-28 18:14

I\'m sure there\'s a good reason, but could someone please explain why the java.util.Set interface lacks get(int Index), or any similar get()

18条回答
  •  庸人自扰
    2020-11-28 18:35

    If you don't mind the set to be sorted then you may be interested to take a look at the indexed-tree-map project.

    The enhanced TreeSet/TreeMap provides access to elements by index or getting the index of an element. And the implementation is based on updating node weights in the RB tree. So no iteration or backing up by a list here.

提交回复
热议问题