A Queue that ensure uniqueness of the elements?

前端 未结 8 1307
甜味超标
甜味超标 2020-12-13 08:25

I\'m looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique.

8条回答
  •  猫巷女王i
    2020-12-13 08:37

    I am a bit late to answer but I ended up solving a similar problem using an ArrayDeque and overriding the add method that I needed.

        Deque myQueue = new ArrayDeque() {
            @Override
            public boolean add(Long e) { return !this.contains(e) && super.add(e);}
        };
    

提交回复
热议问题