I know that there is a removeEldestEntry method that I have to override
This statement is not true because LinkedHashSet HAS-A is LinkedHashMap , not IS-A.
You can use the useful (albeit not very well-known) Collections.newSetFromMap method:
Set<String> mySet = Collections.newSetFromMap(new LinkedHashMap<String, Boolean>(){ protected boolean removeEldestEntry(Map.Entry<String, Boolean> eldest) { return size() > MAX_ENTRIES; } });
In this way, it will return the Set LinkedHashMap (Set-Like interface) view, implementing your own removeEldestEntry method.
MAX_ENTRIES is a custom constant that you would define.
source share