Under certain situations, I need to evict the oldest element in a Java Set. The set is implemented using a LinkedHashSet, which makes this simple: just get rid of t
Set
if (!mySet.isEmpty()) mySet.remove(mySet.iterator.next());
seems to be less than 3 lines.
You have to synchronize around it of course if your set is shared by multiple threads.