Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
ArrayDeque push() Method in Java
Next article icon

ArrayDeque push() Method in Java

Last Updated : 10 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The Java.util.ArrayDeque.push(E element) method is used to push an element into the Deque. The operation is similar to the operation in the stack. The element gets pushed onto the top of the deque. Syntax:
Array_Deque.push(E element)
Parameters: The parameter element is of the type ArrayDeque and refers to the element to be pushed into the deque. Return Value: The method does not return any value. Exceptions: The method throws NullPointerException if the passed parameter is NULL. Below programs illustrate the Java.util.ArrayDeque.push() method: Program 1: Adding String elements into the Deque. Java
// Java code to illustrate push() import java.util.*;  public class ArrayDequeDemo {     public static void main(String args[])     {         // Creating an empty ArrayDeque         Deque<String> de_que = new ArrayDeque<String>();          // Use add() method to add elements into the Deque         de_que.add("Welcome");         de_que.add("To");         de_que.add("Geeks");         de_que.add("4");         de_que.add("Geeks");          // Displaying the initial ArrayDeque         System.out.println("Initial Deque: " + de_que);          // Pushing elements into the deque         de_que.push("Hello");         de_que.push("World");          // Displaying the final ArrayDeque         System.out.println("Final Deque: " + de_que);     } } 
Output:
  Initial Deque: [Welcome, To, Geeks, 4, Geeks]  Final Deque: [World, Hello, Welcome, To, Geeks, 4, Geeks]  
Program 2: Adding Integer elements into the Deque. Java
// Java code to illustrate push() import java.util.*;  public class ArrayDequeDemo {     public static void main(String args[])     {         // Creating an empty ArrayDeque         Deque<Integer> de_que = new ArrayDeque<Integer>();          // Use add() method to add elements into the Deque         de_que.add(10);         de_que.add(15);         de_que.add(30);         de_que.add(20);         de_que.add(5);          // Displaying the initial ArrayDeque         System.out.println("Initial Deque: " + de_que);          // Pushing elements into the deque         de_que.push(1254);         de_que.push(4521);          // Displaying the final ArrayDeque         System.out.println("Final Deque: " + de_que);     } } 
Output:
  Initial Deque: [10, 15, 30, 20, 5]  Final Deque: [4521, 1254, 10, 15, 30, 20, 5]  

Next Article
ArrayDeque push() Method in Java

C

chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java-Collections
  • Java - util package
  • Java-Functions
  • Java-ArrayDeque
Practice Tags :
  • Java
  • Java-Collections
  • Misc

Similar Reads

    ArrayDeque getLast() Method in Java
    The java.util.ArrayDeque.getLast() method in Java is used to retrieve or fetch the last element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the last element of the deque.Syntax: Array_Deque.getLast() Parameters: The method does not
    2 min read
    ArrayDeque isEmpty() Method in Java
    The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if th
    2 min read
    ArrayDeque toArray() Method in Java
    The java.util.ArrayDeque.toArray() method is used to form an array of the same elements as that of the Deque. Basically, the method copies all the element from this deque to a new array. Syntax: Object[] arr = Array_Deque.toArray() Parameters: The method does not take any parameters. Return Value: T
    2 min read
    ArrayDeque offer() Method in Java
    The Java.util.ArrayDeque.offer(Object element) method in Java is used to add a specific element at the end of the Deque. The function is similar to the offerLast() method of ArrayDeque in Java. Syntax: Array_Deque.offer(Object element) Parameters: The parameter element is of the type ArrayDeque and
    2 min read
    ArrayDeque offerFirst() Method in Java
    The Java.util.ArrayDeque.offerFirst(Object element) method in Java is used to add a specific element at the front of the Deque. The function is similar to the addFirst() method of ArrayDeque in Java. Syntax: Array_Deque.offerFirst(Object element) Parameters: The parameter element is of the type Arra
    2 min read
    ArrayDeque offerLast() Method in Java
    The Java.util.ArrayDeque.offerLast(Object element) method in Java is used to add a specific element at the end of this Deque. The function is similar to the addLast(), add() and offer() method of ArrayDeque in Java. Syntax: Array_Deque.offerLast(Object element) Parameters: The parameter element is o
    2 min read
    ArrayDeque peek() Method in Java
    The java.util.ArrayDeque.peek() method in Java is used to retrieve or fetch the element at the head of the Deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque then Null is returned. Syntax: Array_Deque.
    2 min read
    ArrayDeque peekFirst() Method in Java
    The java.util.ArrayDeque.peekFirst() method in Java is used to retrieve or fetch the first element of the deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque or it is empty, then Null is returned. Synta
    2 min read
    ArrayDeque peekLast() Method in Java
    The java.util.ArrayDeque.peekLast() method in Java is used to retrieve or fetch the last element of the deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque or it is empty, then Null is returned. Syntax:
    2 min read
    ArrayDeque poll() Method in Java
    The java.util.ArrayDeque.poll() method in Java is used to retrieve or fetch and remove the element present at the head of the Deque. The peek() method only retrieved the element at the head but the poll() also removes the element along with the retrieval. It returns NULL if the deque is empty. Synta
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences