轻松扩展LinkedHashMap类完成LRU算法ITeye - 牛牛娱乐

轻松扩展LinkedHashMap类完成LRU算法ITeye

2019年02月23日08时08分46秒 | 作者: 翠彤 | 标签: 明白,文档,源码 | 浏览: 3025


     详细关于LinkedHashMap 的描绘 不明白的自己去看 jdk api 文档,这儿只说说怎样完成,翻开LinkedHashMap 源码 咱们能够看到一段描绘:
/**
* Returns tt true /tt if this map should remove its eldest entry.
* This method is invoked by tt put /tt and tt putAll /tt after
* inserting a new entry into the map. It provides the implementor
* with the opportunity to remove the eldest entry each time a new one
* is added. This is useful if the map represents a cache: it allows
* the map to reduce memory consumption by deleting stale entries.
* p Sample use: this override will allow the map to grow up to 100
* entries and then delete the eldest entry each time a new entry is
* added, maintaining a steady state of 100 entries.
* pre 
* private static final int MAX_ENTRIES = 100;
* protected boolean removeEldestEntry(Map.Entry eldest) {
* return size() MAX_ENTRIES;
protected boolean removeEldestEntry(Map.Entry K,V eldest) {
return false;
}
 
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表牛牛娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章