Inserting into Sorted LinkedList Java

前端 未结 7 1285
闹比i
闹比i 2021-01-02 11:59

I have this code below where I am inserting a new integer into a sorted LinkedList of ints but I do not think it is the \"correct\" way of doing things as I know there are s

7条回答
  •  囚心锁ツ
    2021-01-02 12:31

    Have a look at com.google.common.collect.TreeMultiset.

    This is effectively a sorted set that allows multiple instances of the same value.

    It is a nice compromise for what you are trying to do. Insertion is cheaper than ArrayList, but you still get search benefits of binary/tree searches.

提交回复
热议问题