zoukankan      html  css  js  c++  java
  • LinkedHashMap 作为一个 CacheMap

    今天我想实现一个定数的map,搜索Java Map的实现类,发现了下面的说明:

    url: https://docs.oracle.com/javase/tutorial/collections/implementations/map.html

    LinkedHashMap provides two capabilities that are not available with LinkedHashSet. When you create a LinkedHashMap, you can order it based on key access rather than insertion. In other words, merely looking up the value associated with a key brings that key to the end of the map. Also, LinkedHashMap provides the removeEldestEntry method, which may be overridden to impose a policy for removing stale mappings automatically when new mappings are added to the map. This makes it very easy to implement a custom cache.

    For example, this override will allow the map to grow up to as many as 100 entries and then it will delete the eldest entry each time a new entry is added, maintaining a steady state of 100 entries.

    private static final int MAX_ENTRIES = 100;
    
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return size() > MAX_ENTRIES;
    }
  • 相关阅读:
    tar压缩
    sh脚本的dos和unix
    hive常用函数
    hive的union问题
    hive行转多列LATERAL VIEW explode
    Iterator和Enumeration
    基础啊基础
    一道考题---当n=1,2,3...2015时,统计3n+n3能整除7的个数
    自然语言处理
    矩阵相乘
  • 原文地址:https://www.cnblogs.com/evanxyhu/p/LinkedHashMap_as_cacheMap.html
Copyright © 2011-2022 走看看