Java tutorial
//package com.java2s; import java.util.LinkedHashMap; import java.util.Map; public class Main { public static <E, V> Map<E, V> newBoundedMap(final int maxSize) { return new LinkedHashMap<E, V>() { private static final long serialVersionUID = 1L; protected boolean removeEldestEntry(Map.Entry eldest) { return this.size() > maxSize; } }; } }