Do not call this a queue, because by definition, a queue is only the first in the first data structure.
Depending on your input values, I believe that you should use an array and a hash function. The hash determines which index the element is located using its value, and vice versa, i.e. When specifying an index, it returns the value contained in it.
Since you use a hash, repetition is avoided in a collision, that is, you can check if a value previously existed in the index and if it has the same value or not.
C ++ stl has a nice class to set up, although java I don't think it is. But the point is set, it does not offer index search.
source share