This sample code will shows the use of LinkedHashMap. The class LinkedHashMap extends teh LinkedHashMap and overrides its removeEldestEntry() method. This method will set the maximum number of elements in the map to 10. If an element is added to the map after this capacity, one element gets deleted which was added very first.

 import java.util.LinkedHashMap;
import java.util.Map.Entry;

public class LnkdHshMap extends LinkedHashMap {

    private static final long serialVersionUID = 1L;

    protected boolean removeEldestEntry(Entry arg0) {
        return size() > 10;