void () { LongLinkedHashMap<String> map = new LongLinkedHashMap<>(10, 1, true) { @Override protected boolean removeEldestEntry(Entry<String> eldest) { return size() > 3; } }; map.put(1, "1"); map.put(2, "2"); map.put(3, "3"); map.put(4, "4"); Assert.assertEquals(3, map.size()); Assert.assertNull(map.get(1)); Assert.assertEquals("2", map.get(2)); Assert.assertEquals("3", map.get(3)); Assert.assertEquals("4", map.get(4)); }