How to convert ArrayList<String> to String[] in Java

0 votes

Can anybody suggest a way in which I can convert an ArrayList<String> to a String[] in Java? Please help!!

May 21, 2018 in Java by 93.lynn
• 1,560 points
67 views

2 answers to this question.

0 votes

You can try using this:

List<String> list = ..; 

//Add items to your list

list.add(“ABC”);

list.add(“XYZ”);

String[] arrayName = list.toArray(new String[0]);

toArray() method will return an array containing all of the elements in the list in a proper sequence.

answered May 21, 2018 by geek.erkami
• 2,320 points
0 votes

Try this: 

String[] strArray = arrayList.toArray(new String[arrayList.size()]);

answered Aug 21 by Sirajul
• 25,220 points

Related Questions In Java

0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20 in Java by Sirajul
• 25,220 points
131 views
+14 votes
18 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7 in Java by Suresh
• 700 points
77,365 views
0 votes
2 answers

How to convert an int array to string using tostring method in java?

Use java.util.Arrays: String res = Arrays.toString(array); System.o ...READ MORE

answered Aug 16 in Java by Sirajul
• 25,220 points
205 views
0 votes
2 answers

How to convert a JSON String into Object in Java?

You could probably check out Google's Gson: ...READ MORE

answered Aug 21 in Java by Sirajul
• 25,220 points
286 views
0 votes
2 answers
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
57 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
48 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
319 views
0 votes
2 answers

How to move or copy a file in Java

The new JAVA Specification Request 203 -NIO will ...READ MORE

answered Aug 20 in Java by Sirajul
• 25,220 points
33 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 4, 2018 in Java by geek.erkami
• 2,320 points
195 views