A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/concurrentlinkeddeque-push-method-in-java-with-examples/ below:

ConcurrentLinkedDeque push() method in Java with Examples

ConcurrentLinkedDeque push() method in Java with Examples

Last Updated : 11 Jul, 2025

The

push()

method of

ConcurrentLinkedDeque

class is an in-built function in Java which pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Syntax:
public void push(E e)

Here, E is the type of element maintained 
by this collection class.
Parameter:

This method accepts only a single parameter

element

which is to be added at the head of the ConcurentLinkedDeque.

Return Value:

The function has no return value.

Exception:

The method will throw the following exceptions.

Below programs illustrate the ConcurrentLinkedDeque.push() method:

Program 1:

This program involves a ConcurrentLinkedDeque of Character type.

Java
// Java program to demonstrate push()
// method of ConcurrentLinkedDeque

import java.util.concurrent.*;

public class GFG {
    public static void main(String[] args)
    {
        // Creating an empty ConcurrentLinkedDeque
        ConcurrentLinkedDeque<String> CLD
            = new ConcurrentLinkedDeque<String>();

        // Use push() method to add elements
        CLD.push("Welcome");
        CLD.push("To");
        CLD.push("Geeks");
        CLD.push("For");
        CLD.push("Geeks");

        // Displaying the ConcurrentLinkedDeque
        System.out.println("ConcurrentLinkedDeque: "
                           + CLD);
    }
}
Output:
ConcurrentLinkedDeque: [Geeks, For, Geeks, To, Welcome]
Program 2:

To show NullPointerException.

Java
// Java program to demonstrate push()
// method of ConcurrentLinkedDeque

import java.util.concurrent.*;

public class GFG {
    public static void main(String[] args)
    {
        // Creating an empty ConcurrentLinkedDeque
        ConcurrentLinkedDeque<String> CLD
            = new ConcurrentLinkedDeque<String>();

        // Displaying the ConcurrentLinkedDeque
        System.out.println("ConcurrentLinkedDeque: "
                           + CLD);

        try {

            System.out.println("Trying to add "
                               + "null in ConcurrentLinkedDeque");

            // Use push() method to null element
            CLD.push(null);
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Output:
ConcurrentLinkedDeque: []
Trying to add null in ConcurrentLinkedDeque
java.lang.NullPointerException


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4