Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
The toArray() method of CopyOnWriteArrayListin Java
The toArray() method is used to return an array containing all the elements in this list in proper sequence.
The syntax is as follows −
Object[] toArray()
To work with CopyOnWriteArrayList class, you need to import the following package −
import java.util.concurrent.CopyOnWriteArrayList;
The following is an example to implement CopyOnWriteArrayList class toArray() method in Java−
Example
import java.util.Arrays;
import java.util.concurrent.CopyOnWriteArrayList;
public class Demo {
public static void main(String[] args) {
CopyOnWriteArrayList<Integer> arrList = new CopyOnWriteArrayList<Integer>();
arrList.add(220);
arrList.add(250);
arrList.add(400);
arrList.add(500);
arrList.add(650);
arrList.add(700);
arrList.add(800);
System.out.println("CopyOnWriteArrayList String Representation = " + arrList.toString());
Object[] myArr = arrList.toArray();
System.out.println("Array = "+Arrays.toString(myArr));
}
}
Output
CopyOnWriteArrayList String Representation = [220, 250, 400, 500, 650, 700, 800] Array = [220, 250, 400, 500, 650, 700, 800]
Advertisements
