Home Tutorial Java Collections Arraylist Java arraylist to string array

 
 

Share on Google+Share on Google+
Java arraylist to string array
Posted on: October 23, 2009 at 12:00 AM
Advertisement
This Java Tutorial section we demonstrates how to convert the Java arraylist into the string array

  • arrayList can be converted into string array.
  • For this first converts the arrayList into the object array.
  • This is done by  using the toArray() method.
  • Then cast it into the string and assign in the String array.

import java.util.*;

public class List1 {

public static void main(String[] args) {
String ar[]={"cat","dog","rat","elephant"};
String ar2[]=new String[4];
ArrayList list=new ArrayList();
list.add(ar[0]);
list.add(ar[1]);
list.add(ar[2]);
list.add(ar[3]);
Object obj[]=list.toArray();

for(int x=0;x








					
					
Advertisement

Related Tags for Java arraylist to string array:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com