Home » Java programming language

Java Collections asLifoQueue() Method with Example

Collections Class asLifoQueue() method: Here, we are going to learn about the asLifoQueue() method of Collections Class with its syntax and example.
Submitted by Preeti Jain, on January 07, 2020

Collections Class asLifoQueue() method

  • asLifoQueue() Method is available in java.lang package.
  • asLifoQueue() Method is used to represent the given deque as a Lifo queue (LIFO means Last-in-First-Out).
  • asLifoQueue() Method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • asLifoQueue() Method does not throw an exception at the time of conversion from given Deque to LIFO Queue.

Syntax:

    public static Queue asLifoQueue(Deque d);

Parameter(s):

  • Deque d – represent the Deque.

Return value:

The return type of the method is Queue, it returns LIFO Queue.

Example:

// Java Program is to demonstrate the example
// of Queue asLifoQueue(Deque d) method of Collections class

import java.util.*;

public class AsLifoQueue {
    public static void main(String args[]) {
        // Create a array deque object    
        Deque de = new ArrayDeque(10);

        // By using add() method is to add the
        // given elements in linked list
        de.add("C");
        de.add("C++");
        de.add("JAVA");
        de.add("DOTNET");
        de.add("PYTHON");

        // Display Deque
        System.out.println("de: " + de);

        // By using asLifoQueue() method is to 
        // represent the deque elements as lifo queue

        Queue lifo_q = Collections.asLifoQueue(de);

        System.out.println();
        System.out.println("Collections.asLifoQueue(de) :");

        // Display Queue
        System.out.println("lifo_q: " + lifo_q);
    }
}

Output

de: [C, C++, JAVA, DOTNET, PYTHON]

Collections.asLifoQueue(de) :
lifo_q: [C, C++, JAVA, DOTNET, PYTHON]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.