Home » Java Deque peek() Method with Examples

Java Deque peek() Method with Examples

by Online Tutorials Library

Java Deque peek () Method

The peek() method of Java Deque Interface is used to retrieve but not to remove the head of the deque. The method may return null if the given deque is empty.

Specified by:

  • peek in interface Queue<E>

Syntax:

Parameter:

NA

Return:

The above method is used to return the head of the deque which is represented by the queue. On the other hand, if the deque is empty, the method may return null.

Example 1

Test it Now

Output:

The first character is given as : J  The deque is :   J  A  V  A  T  P  O  I  N  T  

Example 2

Test it Now

Output:

The first string is given as : Hello  The deque is : [Hello,  , World]  

Example 3

Test it Now

Output:

The first long value is given as : 88  The resultant deque is : [88, 78, 67]  
Next TopicJava Deque

You may also like