Why is there no SortedList in Java?

后端 未结 12 928
猫巷女王i
猫巷女王i 2020-11-22 04:15

In Java there are the SortedSet and SortedMap interfaces. Both belong to the Java Collections framework and provide a sorted way to access the elements.

However, in

12条回答
  •  無奈伤痛
    2020-11-22 04:57

    Think of it like this: the List interface has methods like add(int index, E element), set(int index, E element). The contract is that once you added an element at position X you will find it there unless you add or remove elements before it.

    If any list implementation would store elements in some order other than based on the index, the above list methods would make no sense.

提交回复
热议问题