Java Deque getLast() Method

The getLast() method of Java Deque Interface retrieves but not remove the last element of the deque. The above method differs from the peekLast only in one way that it throws an exception only if the deque is empty.

Syntax:

Parameter:

N.A.

Return:

The above method is used to return the tail of the deque.

Throw:

NoSuchElementException- If the given deque is empty.

Example 1

Test it Now

Output:

The final queue is : [FAT, CAO, JAVA, DBMS]
The required answer : DBMS

Example 2

Test it Now

Output:

The list of the elements is given as : 
[k, p, m, t]
The required answer : t

Example 3

Test it Now

Output:

The list of the elements is given as : [2, 3, 4, 5]
The required answer : 5
Next TopicJava Deque




Latest Courses