toArray() Object Method : Java.util.ArrayList
Declaration :
1 |
public Object[] toArray() |
Explanation :
Purpose | Method returns an array containing all of the elements in this list in proper sequence |
Parameters | NA |
Return Value | Returns an array containing all of the elements in this list in sequence |
Exception | NA |
Example
The following example shows the usage of java.util.Arraylist.toarray() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package com.c4learn.arraylist; import java.util.ArrayList; public class ArrayListExamples { public static void main(String args[]) { // Create ArrayList 1 ArrayList<String> arrlist1 = new ArrayList<String>(5); // Fill Elements in ArrayList 1 arrlist1.add("A"); arrlist1.add("B"); arrlist1.add("C"); // Object Array Object[] ob = arrlist1.toArray(); System.out.println("Printing List elements : "); for (Object value : ob) { System.out.println("List Element : " + value); } } } |
Output :
1 2 3 4 |
Printing List elements : List Element : A List Element : B List Element : C |