」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 為什麼Java沒有SortedList?

為什麼Java沒有SortedList?

發佈於2025-03-23
瀏覽:302

Why Doesn't Java Have a SortedList?
為什麼Java缺少sortedList

在Java Collections Framework中不同,Java在Java Collections Framework中不提供DEDICATICETICETICETICETEDLIST。儘管存在如此遺漏,但Java確實通過Java.util.collections.sort()方法提供分類功能。

的原因

缺乏從列表it iTererator的基礎性質的sortedList詞幹。列出迭代器優先保留元素的插入順序。 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):

    SortedSet automates在元素插入過程中進行排序,消除對手動排序的需求。
  1. treemultiset(多式實現)允許在保留排序順序時進行重複元素。

    接受定制排序的比較器,例如,允許區域敏感的字符串排序。 PriorityQueue provides a sorted queue behavior suitable for certain use cases.

    Iteration through a PriorityQueue returns elements in sorted order.
    Custom Implementation:
  2. Users can create their own SortedList by extending the AbstractList class and覆蓋添加和排序方法。 此選項不建議使用,因為它違反了列表接口合同,並且對現有解決方案沒有明顯的優勢。 [&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& && && && &&&華

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3