zoukankan      html  css  js  c++  java
  • LinkedHashMap简明

    LinkedHashMap

    构造方法摘要

    inkedHashMap()

    构造一个带默认初始容量 (16) 和加载因子 (0.75) 的空插入顺序 LinkedHashMap 实例。

    LinkedHashMap(int initialCapacity)

    构造一个带指定初始容量和默认加载因子 (0.75) 的空插入顺序 LinkedHashMap 实例。

    LinkedHashMap(int initialCapacity, float loadFactor)

    构造一个带指定初始容量和加载因子的空插入顺序 ·LinkedHashMap· 实例。

    LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)

    构造一个带指定初始容量、加载因子和排序模式的空 LinkedHashMap 实例。 accessOreder : false(默认)为插入顺序, true 为访问顺序。

    LinkedHashMap(Map<? extends K,? extends V> m)

    构造一个映射关系与指定映射相同的插入顺序 LinkedHashMap 实例。


    tips

    如果调用LinkedHashMap(initialCapacity, loadFactor, true),每次用get或put时,受影响的条目将从当前位置删除,并放到链表的尾部(散列表中的桶不会受影响,一个条目总位于其散列码对应的桶中)。

    public class LinkedHashMapT {
    
    	public static void main(String[] args) {
    		LinkedHashMap<String, String> lhMap = new LinkedHashMap<>(16, 0.75F, true);
    		lhMap.put("111", "111");
    		lhMap.put("222", "222");
    		lhMap.put("333", "333");
    		lhMap.put("444", "444");
    		lhMap.put("555", "555");
    		lhMap.put("666", "666");
    		loopLinkedHashMap(lhMap);
    		loopLinkedHashMap(lhMap);
    		loopLinkedHashMap(lhMap);
    		lhMap.get("333");
    		loopLinkedHashMap(lhMap);
    		lhMap.put("222", "222");
    		loopLinkedHashMap(lhMap);
    		lhMap.put("777", "777");
    		loopLinkedHashMap(lhMap);
    	
    	}
    	public static void loopLinkedHashMap(LinkedHashMap<String, String> linkedhashMap){
    		Set<Map.Entry<String,String>> set = linkedhashMap.entrySet();
    		Iterator<Map.Entry<String, String>> it = set.iterator();
    		while(it.hasNext()){
    			System.out.print(it.next() + "\t");
    		}
    		System.out.println();
    	}
    }
    
    111=111	222=222	333=333	444=444	555=555	666=666	
    111=111	222=222	333=333	444=444	555=555	666=666	
    111=111	222=222	333=333	444=444	555=555	666=666	
    111=111	222=222	444=444	555=555	666=666	333=333	
    111=111	444=444	555=555	666=666	333=333	222=222	
    111=111	444=444	555=555	666=666	333=333	222=222	777=777	
    

    LRUCache

    • 构造LinkedHashMap的子类
    • 覆盖方法:protected boolean removeEldestEntry(java.util.Map.Entry<K,V> eldest)
    public class LRUCache extends LinkedHashMap
    {
    	private static final long serialVersionUID = 1L;
        protected int maxElements;
        public LRUCache(int maxSize)
        {
            super(maxSize, 0.75F, true);
            maxElements = maxSize;
        }
    
        protected boolean removeEldestEntry(java.util.Map.Entry eldest)
        {
            return size() > maxElements;
        }
    }
    
  • 相关阅读:
    商量Oracle数据库的数据导入办法2
    设置sql中止跟踪
    Oracle平台运用数据库系统的规划与拓荒2
    Oracle漫衍式系统数据复制技艺1
    商议Oracle数据库的数据导入措施1
    Oracle数据库等分区表的操纵方式2
    Oracle数据库集中复制方式浅议
    Oracle分布式细碎数据复制技艺2
    根绝平静隐患 随便无视的Oracle平静成绩
    优化Oracle库表筹算的若干方法2
  • 原文地址:https://www.cnblogs.com/LittleTreasureBox/p/8799362.html
Copyright © 2011-2022 走看看