简体   繁体   中英

Efficient java data structure to delete and retrieve information?

I have a situation where I have need a data structure that I can add strings to. This data structure is very large.

The specific qualities I need it have are:

  1. get(index)
  2. delete a certain number of entries that were added initially when the limit exceeds.(LIFO)

I've tried using an ArrayList but the delete operation is o(n) and for a linkedList the traverse or get() operation will be o(n).

What other options do I have?

循环缓冲区 -在引擎盖下使用数组实现的缓冲

LinkedHashSet might be of interest. It is effectively a HashSet but it also maintains a LinkedList to allow a predictable iteration order - and therefore can also be used as a FIFO queue, with the nice added benefit that it can't contain duplicate entries.

Because it is a HashSet too, searches (as opposed to scans) can be O(1) if they can match on equals()

You can have a look at this question and this too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM