简体   繁体   English

仅存储最近n个条目的字典或类似数据结构?

[英]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. 我想知道是否有一个内置的Java数据结构,其行为类似于字典, 仅保留固定数量的最新条目。 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. 您可以通过扩展LinkedHashMap轻松地创建一个。 When adding an entry, check the size and remove the oldest item if already at maximum size. 添加条目时,检查尺寸并删除最旧的项目(如果已经达到最大尺寸)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HashMap只包含最近的条目 - HashMap with only most recent entries 字典条目数组的数据结构 - Data Structure for an array of Dictionary entries 固定大小的日志文件,仅包含最新条目 - Fixed size log file containing only the most recent entries 是否存在仅存储哈希码而不存储实际对象的数据结构? - Is there a data structure that only stores hash codes and not the actual objects? 仅对最新的异步更新数据运行计算 - Run computation on only the most recent, asynchronously updating data 在Java中查询集合中的最新条目 - Query the most recent entries in a collection in Java MongoDB 的自动生成 Spring 数据查询:X 个最近的条目 - Auto-Generated Spring data query for MongoDB: X most recent entries 在Java中,哪个是字典数据结构最推荐的类? - In Java, which is the most recommended class for a dictionary data structure? 如何创建一个数组循环,其中只绘制最近的 n 个粒子? - How do I create an array loop where only the most recent n particles are drawn? 如何建立一个可以在时间戳上保存100个最新record_values基础的数据结构? - How to make a data structure which can hold 100 most recent record_values basis on timestamp?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM