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
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
No comments:
Post a Comment