public LinkedHashMap (int initialCapacity, float loadFactor, boolean accessOrder);
initialCapacity 初始容量
loadFactor 加载因子,一般是 0.75f
accessOrder false 基于插入顺序 true 基于访问顺序(get一个元素后,这个元素被加到最后,使用了LRU 最近最少被使用的调度算法)
boolean accessOrder = true; Map<String, String> m = new LinkedHashMap<String, String>(20, .80f,accessOrder); m.put("1", "test1"); m.put("2", "test2"); m.put("3", "test3"); System.out.println(m); //{1=test1, 2=test2, 3=test3}
Map<String, String> m = new LinkedHashMap<String, String>(20, .80f,accessOrder); m.put("1", "test1"); m.put("2", "test2"); m.put("3", "test3"); m.get("1"); m.get("2"); System.out.println(m); //{3=test3, 1=test1, 2=test2}
boolean accessOrder = false; Map<String, String> m = new LinkedHashMap<String, String>(20, .80f,accessOrder); m.put("1", "test1"); m.put("2", "test2"); m.put("3", "test3"); System.out.println(m); //{1=test1, 2=test2, 3=test3}
boolean accessOrder = false; Map<String, String> m = new LinkedHashMap<String, String>(20, .80f,accessOrder); m.put("1", "test1"); m.put("2", "test2"); m.put("3", "test3"); m.get("1"); m.get("2"); System.out.println(m); //{1=test1, 2=test2, 3=test3}
时间: 2024-10-13 06:48:26