Java CopyOnWriteArrayList toArray() MethodThe toArray() method of Java CopyOnWriteArrayList class returns an array which contains all of the elements in this list in proper sequence from first to the last element. The toArray() method acts as a bridge between array-based and collection-based APIs. Syntax:Returns:This method returns an array which contains all the elements in this list. Example 1Test it NowOutput: Array List is : [1, 2, 1, 4, 5, 3, 3, 8] Example 2Test it NowOutput: Array List is : [] Example 3Test it NowOutput: Array List is : [Tom, Harry, John, John, John, Jerry] Example 4Test it NowOutput: Array List is : [] Java CopyOnWriteArrayList<E>toArray(T[] a) Method:The toArray(T[] a) method of Java CopyOnWriteArrayList class returns an array which contains all of the elements in this list in proper sequence from first to the last element. The runtime type of the returned array is that of the specified array. This method returns therein if the list fits in the specified array. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. Syntax:Parameters:a - It is the array into which the elements of the list are to be stored. Returns:This method returns an array which contains all the elements in this list. Example 1Test it NowOutput: Array List is : [1, 2, 1, 4, 5, 3, 3, 8, null, 6, 6, 6, 6, 6, 6] Example 2Test it NowOutput: Array List is : [1, 2, 1, 4, 5, 3, 3, 8] Example 3Test it NowOutput: Array List is : [Tom, Harry, John, John, John, Jerry, null, 6, 6, 6, 6, 6, 6] Example 4Test it NowOutput: Array List is : [Tom, Harry, John, John, John, Jerry] Next TopicJava CopyOnWriteArrayList |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India