0% found this document useful (0 votes)
5 views1 page

ArrayDeque Stack Example in Java

This document demonstrates how to use an ArrayDeque in Java like a stack. It creates an ArrayDeque of strings, pushes strings "A" through "F" onto the deque, then pops and prints each string off the deque in reverse order, demonstrating the LIFO behavior of a stack.

Uploaded by

Treymax Sikan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

ArrayDeque Stack Example in Java

This document demonstrates how to use an ArrayDeque in Java like a stack. It creates an ArrayDeque of strings, pushes strings "A" through "F" onto the deque, then pops and prints each string off the deque in reverse order, demonstrating the LIFO behavior of a stack.

Uploaded by

Treymax Sikan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

// Demonstrate ArrayDeque.

import [Link].*;
class ArrayDequeDemo {
public static void main(String args[])
{
// Create an array deque.
ArrayDeque<String> adq = new
ArrayDeque<String>();
// Use an ArrayDeque like a stack.
[Link]("A");
[Link]("B");
[Link]("D");
[Link]("");
[Link]("F");
[Link]("Popping the stack:
");
while([Link]() != null)
//[Link]([Link]());
[Link]([Link]() + " ");
[Link]();
}
}

You might also like