简体   繁体   中英

Dictionary or similar data structure that only stores the most recent n entries?

I'm wondering if there's a built-in Java data structure that behaves like a dictionary but only keeps a fixed number of recent entries. So I could keep the size more-or-less constant but also have it behave like a dictionary or hashmap.

You could create one quite easily by extending LinkedHashMap. When adding an entry, check the size and remove the oldest item if already at maximum size.

我认为LRUMap将适合您的需求。

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