Why is there no SortedList in Java?

后端 未结 12 941
猫巷女王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 05:13

    Because the concept of a List is incompatible with the concept of an automatically sorted collection. The point of a List is that after calling list.add(7, elem), a call to list.get(7) will return elem. With an auto-sorted list, the element could end up in an arbitrary position.

提交回复
热议问题