Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a particular element from Queue?

Unlike ArrayList, there is no get(int index) method in Queue to retrieve the element at specified position.

Anybody please tell me how to achieve this in Queue?

Thanks.

like image 287
user1612078 Avatar asked Mar 17 '14 12:03

user1612078


People also ask

How do I find my queue element?

The element() method of Queue Interface returns the element at the front the container. It does not deletes the element in the container. This method returns the head of the queue. This method differs from peek() only in that it throws an exception if this queue is empty.

How do you pop an element from a queue in Java?

To remove elements from a Java Queue , you call the remove() method. This method removes the element at the head of the Queue .

How do I remove a specific item from a queue?

To remove an element from a Queue, use the remove() method.

How do you pop an element from a queue in Python?

Removing an item from a queue in Python: To remove items from a queue in Python, we will be using the “get function”. See the Python Queue example given below. To make sure that our queue is empty, we can use the empty function which will return Boolean values.


1 Answers

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 queue.

like image 84
RKC Avatar answered Sep 18 '22 18:09

RKC