Why is there no SortedList in Java?

后端 未结 12 790
猫巷女王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:52

    First line in the List API says it is an ordered collection (also known as a sequence). If you sort the list you can't maintain the order, so there is no TreeList in Java.
    As API says Java List got inspired from Sequence and see the sequence properties http://en.wikipedia.org/wiki/Sequence_(mathematics)

    It doesn't mean that you can't sort the list, but Java strict to his definition and doesn't provide sorted versions of lists by default.

提交回复
热议问题