How to convert Given Array List to Array of Strings

This is the simple java program that convert array list into array of strings for example if we have data stored in Array List and for some reason we have to convert it in to array of strings.

Source Code 


package lep;
import java.util.ArrayList;
/**
 * @author Uzair
 */
public class ArrayListToStringArray {

public static void main(String args[]) {
System.out.println("\n\n\n"
+"\t*******************************************************\n"
+"\t** **\n"
+"\t** Welcome To **\n"
+"\t** **\n"
+"\t** ArrayList<String> To String[] **\n"
+"\t** **\n"
+"\t** Conversion Program **\n"
+"\t** **\n"
+"\t*******************************************************\n");
System.out.println("\t\t\t");

//ArrayList<String> to store list of strings
ArrayList<String> all_types = new <String>ArrayList();
all_types.add("One");
all_types.add("Two");
all_types.add("Three");
all_types.add("Other");

//String[] is an array of string
String[] itemArr = new String[all_types.size()];
itemArr = all_types.toArray(itemArr);

System.out.println(" Displaying String : ");
for(String s : itemArr)
System.out.println(s);
}
}

Output of the Program

convert Given Array List to Array of Strings



Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment