- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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]
- Related Articles
- The clear() method of CopyOnWriteArrayListin Java
- The toArray() method of AbstractSequentialList in Java
- The toArray() method of Java AbstractCollection class
- The toArray(T[]) method of AbstractSequentialList in Java
- IntStream toArray() method in Java
- LongStream toArray() method in Java
- ArrayBlockingQueue toArray() Method in Java
- DoubleStream toArray() method in Java
- The toArray(T[] a) method of CopyOnWriteArrayList in Java
- What does the method toArray() do in java?
- The toArray(T[] a) T method of Java AbstractCollection class
- jQuery Misc toArray() Method
- What does the method toArray() do?
- Ints toArray() function in Java
- The isEmpty() method of CopyOnWriteArrayList method in Java

Advertisements