Java Deque element() MethodThe 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 1Test it NowOutput: The final queue is : [FAT, CAO, JAVA, DBMS] The required answer : FAT Example 2Test it NowOutput: The list of the elements is given as : [k, p, m, t] The required answer : k Example 3Test it NowOutput: The list of the elements is given as : [2, 3, 4, 5] The required answer : 2 Next TopicJava Deque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India