A Queue that ensure uniqueness of the elements?

How about a LinkedHashSet? Its iterator preserves insertion order, but because it’s a Set, its elements are unique.

As its documentation says,

Note that insertion order is not affected if an element is re-inserted into the set.

In order to efficiently remove elements from the head of this “queue”, go through its iterator:

Iterator<?> i = queue.iterator();
...
Object next = i.next();
i.remove();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)