Java ArrayDeque pop and peek element

Introduction

To pop and peek element in ArrayDeque in Java

while(adq.peek() != null) {
   System.out.println(adq.pop() + " ");
}

Full source


import java.util.ArrayDeque; 
 
public class Main { 
  public static void main(String args[]) { 
    ArrayDeque<String> adq = new ArrayDeque<String>(); 
     /*  w ww  .j a v  a 2 s  . c  o  m*/
    // Use an ArrayDeque like a stack.
    adq.push("CSS"); 
    adq.push("HTML");  
    adq.push("Java"); 
    adq.push("Javascript"); 
    adq.push("SQL"); 
 
    System.out.println(adq);
    

    System.out.println("Popping the stack: ");

    while(adq.peek() != null) {
      System.out.println(adq.pop() + " ");
    }
  } 
}



PreviousNext

Related