AbstractQueue element() method in Java with examples
The element() method of AbstractQueue retrieves, but does not remove, the head of this queue.
public E element()
Parameters: This method does not accept any parameters.
Returns: The method returns the head of the Queue.
Exception: The function throws an NoSuchElementException if the queue is empty.
Below programs illustrate element() method:
AbstractQueue1 contains : [10, 20, 30, 40, 50] head : 10
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.