javaqueue

How do I get the nth item in a Queue?


I have a number of queues and priority queues in my application. I would like to easily access the nth items in these queues, but don't see an easy way to do that using the API.

I guess I could create an Iterator and iterate to the nth element or use toArray()[index], but it seems like there should be an easier way.

Am I missing something?


Solution

  • Am I missing something?

    Yes - the fact that accessing elements by index is not part of the concept of a queue.

    If you need to access elements by index, you want a list, not a qeue.