How To Copy LinkedList To Array

import java.util.LinkedList;

public class LinkedListToArray {

public static void main(String[] args) {

LinkedList<String> linkedList = new LinkedList<String>();

linkedList.add(“Mumbai”);
linkedList.add(“Delhi”);
linkedList.add(“Noida”);
linkedList.add(“Gao”);
linkedList.add(“Patna”);

String [] arr = new String[linkedList.size()];

linkedList.toArray(arr);
for (String str : arr) {

System.out.println(“Element  is =”+str);

}

}

}

Output:

Element  is =Mumbai

Element  is =Delhi

Element  is =Noida

Element  is =Gao

Element  is =Patna

Leave a Reply

Your email address will not be published. Required fields are marked *

− 1 = 3