How to convert ArrayList to String array and String array to ArrayList

Converting ArrayList to String Array
public static String[] convertArrayListToStringArray
(ArrayList<String> arrayList)
 {
 String[] stringArray = new String[0];
 if(arrayList!=null)
 {
 try
 {
 stringArray = new String[arrayList.size()];
 Arrays.asList(stringArray);
 }
 catch (Exception e)
 {
 }
 }
 return stringArray;
 }

Converting String Array to ArrayList

 public static ArrayList<String> convertArrayListToStringArray
(String[] stringArray)
 {
 ArrayList<String> arrayList = new ArrayList<String>();
 if(stringArray!=null)
 {
 try
 {
 arrayList = new ArrayList<String>(Arrays.asList(stringArray));
 }
 catch (Exception e)
 {
 }
 }
 return arrayList;
 }

Advertisements

Tags: ,

About krishjlk

http://www.facebook.com/krishna.kanth.121

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: