Java ArrayList toArray Example
ArrayList class toArray method example. This example shows you how to use toArray method.
ArrayList class toArray method example.public Object[] toArray() Returns an array containing all of the elements in this list in proper sequence (from first to last element).
Here is the code
/**
* @ # toArray.java
* A class repersenting use to toArray method of ArrayList class in java.util package
* version 14 May 2008
* author Rose India
*/
import java.util.*;
public class ToArray {
public static void main(String args[]) {
List arrlist = new ArrayList();
int i = 0;
String str = "Rose";
//Add the specified element to the end of this list.
arrlist.add(i);
arrlist.add(str);
arrlist.add("India");
System.out.println("arrlist = " + arrlist);
Object arr[]=arrlist.toArray();
for(int a=0;a<arr.length;a++)
System.out.println(arr[a].toString());
}
} |
Output
arrlist = [0, Rose, India]
0
Rose
India |
|