java.util.Collections.asLifoQueue() Method



Description

The asLifoQueue(Deque<T>) method is used to get a view of a Deque as a Last-in-first-out (Lifo) Queue.

Declaration

Following is the declaration for java.util.Collections.asLifoQueue() method.

public static <T> Queue<T> asLifoQueue(Deque<T> deque)

Parameters

deque − This is the deque.

Return Value

The method call returns the queue.

Exception

NA

Example

The following example shows the usage of java.util.Collections.asLifoQueue()

package com.tutorialspoint;

import java.util.*;

public class CollectionsDemo {
   public static void main(String args[]) {
   
      // create Deque object       
      Deque<Integer> deque = new ArrayDeque<Integer>(7);

      // populate the object
      deque.add(1);
      deque.add(2);
      deque.add(3);
      deque.add(4);
      deque.add(5);        
      deque.add(6);
      deque.add(7);

      // get queue from the deque
      Queue nq = Collections.asLifoQueue(deque);      

      System.out.println("View of the queue is: "+nq);
   }    
}

Let us compile and run the above program, this will produce the following result.

View of the queue is: [1, 2, 3, 4, 5, 6, 7]
java_util_collections.htm
Advertisements