This Java Example shows how to copy all elements of LinkedList object to an Array object in java.
Copy LinkedList to an Array object Example
This Java Example shows how to copy all elements of LinkedList object to an
Array object in java. To copy the LinkedList elements to Array object we
use Object[] toArray( ) method. This method returns an array
containing all of the elements in this list in proper sequence.
Example: LinkedListcopytoArray.java
package devmanuals.com;
import java.util.*;
public class LinkedListcopytoArray {
public static void main(String[] args) {
LinkedList LKLST = new LinkedList();
LKLST.add("Gyan");
LKLST.add("Singh");
LKLST.add("Arunesh");
LKLST.add("Kumar");
Object[] obj = LKLST.toArray();
System.out.println("The Array Elements are : ");
for (int i = 0; i < obj.length; i++) {
System.out.println(obj[i]);
}
}
}
Output:
| The Array Elements are :
Gyan Singh Arunesh Kumar |

[ 0 ] Comments