Why Java Lacks a SortedList
Unlike SortedSet and SortedMap in the Java Collections framework, Java does not provide a dedicated SortedList. Despite this omission, Java does offer sorting capabilities through the java.util.Collections.sort() method.
Reasons for the Omission
The absence of a SortedList stems from the fundamental nature of List iterators. List iterators prioritize preserving the insertion order of elements. Sorting, on the other hand, can be viewed as a manipulation of the data structure, altering the element order.
Alternatives to SortedList
SortedSet and Multisets (Bags):
Collections.sort():
PriorityQueue:
Custom Implementation:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3