A good Sorted List for Java

后端 未结 10 1688
离开以前
离开以前 2020-11-30 02:29

I\'m looking for a good sorted list for java. Googling around give me some hints about using TreeSet/TreeMap. But these components is lack of one thing: random access to an

10条回答
  •  情深已故
    2020-11-30 02:45

    What about using a HashMap? Insertion, deletion, and retrieval are all O(1) operations. If you wanted to sort everything, you could grab a List of the values in the Map and run them through an O(n log n) sorting algorithm.

    edit

    A quick search has found LinkedHashMap, which maintains insertion order of your keys. It's not an exact solution, but it's pretty close.

提交回复
热议问题