Why is there no SortedList in Java?

后端 未结 12 789
猫巷女王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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 04:50

    Another point is the time complexity of insert operations. For a list insert, one expects a complexity of O(1). But this could not be guaranteed with a sorted list.

    And the most important point is that lists assume nothing about their elements. For example, you can make lists of things that do not implement equals or compare.

提交回复
热议问题