Java Deque element() MethodLast Updated : 17 Mar 2025 The element() method of Java Deque Interface retrieves but not remove the head of the queue which is represented by the deque. The above method differs from the peek only in one way that it throws an exception only if the deque is empty. Specified by:
Syntax:Parameter:N.A. Return:The above method returns the head of the deque represented by the given deque. Throw:NoSuchElementException- if the given deque is emplty. Example 1Output: The final queue is : [FAT, CAO, JAVA, DBMS] The required answer : FAT Example 2Output: The list of the elements is given as : [k, p, m, t] The required answer : k Example 3Output: The list of the elements is given as : [2, 3, 4, 5] The required answer : 2 Next TopicJava Deque |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India