Last Updated : 17 Sep, 2018
The
putLast(E e)method of
LinkedBlockingDequeinserts the specified element into the queue represented by this deque (in other words, at the tail/end of this deque). If the Deque is capacity restricted, then it will wait for the space to become available.
Syntax:public void putLast(E e)Parameters:
This method accepts a mandatory parameter
ewhich is the element to be inserted at the end of the LinkedBlockingDeque.
Returns:This method does not return anything.
Exceptions:The program throws two exceptions as shown below:
Below programs illustrate putLast() method of LinkedBlockingDeque:
Program 1: Java
// Java Program Demonstrate putLast()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
// Add numbers to end of LinkedBlockingDeque
LBD.putLast(7855642);
LBD.putLast(35658786);
LBD.putLast(5278367);
LBD.putLast(74381793);
// print Dequeue
System.out.println("Linked Blocking Deque: " + LBD);
}
}
Output:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]Program 2: Java
// Java Program Demonstrate putLast()
// method of LinkedBlockingDeque
// throwing NullPointerException
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
// Add numbers to end of LinkedBlockingDeque
LBD.putLast(7855642);
LBD.putLast(35658786);
LBD.putLast(5278367);
// throws an exception
LBD.putLast(null);
// print Dequeue
System.out.println("Linked Blocking Deque: " + LBD);
}
}
Output
:
Runtime Errors: Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.putLast(LinkedBlockingDeque.java:390) at GFG.main(GFG.java:23)Program 3: Java
// Java Program Demonstrate putLast()
// method of LinkedBlockingDeque
// when capacity exceeded
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>(3);
// Add numbers to end of LinkedBlockingDeque
LBD.putLast(7855642);
LBD.putLast(35658786);
LBD.putLast(5278367);
// throws an exception
LBD.putLast(4356789);
// print Dequeue
System.out.println("Linked Blocking Deque: " + LBD);
}
}
Output
:
Runtime Errors: Max real time limit exceeded due to either by heavy load on server or by using sleep functionReference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#putLast-E-
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