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

前端 未结 18 1291
长情又很酷
长情又很酷 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:49

    Because sets have no ordering. Some implementations do (particularly those implementing the java.util.SortedSet interface), but that is not a general property of sets.

    If you're trying to use sets this way, you should consider using a list instead.

提交回复
热议问题