Java LinkedList toArray Example
LinkedList class toArray method example. This example shows you how to use toArray method.
LinkedList 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 LinkedList 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 list = new LinkedList();
int i = 0;
String str = "Rose";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
list.add("India");
System.out.println("list = " + list);
Object arr[]=list.toArray();
for(int a=0;a<arr.length;a++)
System.out.println(arr[a].toString());
}
} |
Output
list = [0, Rose, India]
0
Rose
India |
|