How to use index for O (1) random access sort set

You need a string collection, in which the inserted elements need to be sorted or non repeated, and can be retrieved by index

>I can use TreeSet to delete duplicates and sort all the contents of the order, but I can't retrieve it through the index Through index retrieval, I can create ArrayList and addall elements for it, but this addall takes a lot of time

or

>I can use ArrayList, insert required, then delete duplicates by other methods, and then use collections The sort method sorts the elements

But the question is, all this takes time. Is there any direct way to achieve this, a set - sorted, non repetitive, O (1) random access through index

Solution

There is a data type called setuniquelist in the Commons collection, which I think fully meets your needs Look at this:

https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/list/SetUniqueList.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>