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

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

    java.util.Set is a collection of un-ordered items. It doesn't make any sense if the Set has a get(int index), because Set doesn't has an index and also you only can guess the value.

    If you really want this, code a method to get random element from Set.

提交回复
热议问题