Last Updated : 24 Dec, 2018
public Object[] toArray()Parameters:It does not take in any parameter. Return Value:It returns an array containing all the elements in the deque. Below examples illustrates the ConcurrentLinkedDeque.toArray() method: Example 1: Java
// Java Program Demonstrate toArray()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of ConcurrentLinkedDeque
ConcurrentLinkedDeque<Integer> deque
= new ConcurrentLinkedDeque<Integer>();
// Add numbers to end of ConcurrentLinkedDeque
deque.add(7855642);
deque.add(35658786);
deque.add(5278367);
deque.add(74381793);
System.out.println("ConcurrentLinkedDeque: "
+ deque);
Object[] a = deque.toArray();
System.out.println("Returned Array: "
+ Arrays.toString(a));
}
}
Output:
ConcurrentLinkedDeque: [7855642, 35658786, 5278367, 74381793] Returned Array: [7855642, 35658786, 5278367, 74381793]
public <T> T[] toArray(T[] a)Parameters: The method accepts one parameter arr[] which is the array into which the elements of the ConcurrentLinkedDeque are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose. Return Value: The method returns an array containing the elements similar to the ConcurrentLinkedDeque. Exception: The method might throw two types of exception:
// Java code to illustrate toArray(arr[])
import java.util.concurrent.*;
import java.util.*;
public class ConcurrentLinkedDequeDemo {
public static void main(String args[])
{
// Creating an empty ConcurrentLinkedDeque
ConcurrentLinkedDeque<String> deque
= new ConcurrentLinkedDeque<String>();
// Use add() method to add
// elements into the ConcurrentLinkedDeque
deque.add("Welcome");
deque.add("To");
deque.add("Geeks");
deque.add("For");
deque.add("Geeks");
// Displaying the ConcurrentLinkedDeque
System.out.println("The ConcurrentLinkedDeque: "
+ deque);
// Creating the array and using toArray()
String[] arr = new String[5];
arr = deque.toArray(arr);
// Displaying arr
System.out.println("Returned Array: "
+ Arrays.toString(arr));
}
}
Output:
The ConcurrentLinkedDeque: [Welcome, To, Geeks, For, Geeks] Returned Array: [Welcome, To, Geeks, For, Geeks]
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