0

I'm working on a project where i need to convert either an ArrayList or and Array to an String array. I need each word/string to convert to seperate strings.

Something like this:

public ArrayList<String> arrList2 = new ArrayList<String>();

and then convert it and past into

public String arrList4 [] = new String [250];

Hope this is detaild enough so you get what i want.

tskuzzy
  • 35,812
  • 14
  • 73
  • 140
Fifkie
  • 1
  • 1
  • Possible duplicate of [Convert ArrayList containing Strings to an array of Strings in Java?](http://stackoverflow.com/questions/4042434/convert-arraylist-containing-strings-to-an-array-of-strings-in-java) – bozzmob Jan 14 '16 at 18:22

2 Answers2

2
ArrayList<String> al = new ArrayList<String>();

    al.add("C");
    al.add("java2s.com");
    al.add("D");
    al.add("F");
    al.add(1, "java2s.com");

    String[] strings = al.toArray(new String[al.size()]);
    System.out.println(Arrays.toString(strings));

Here is an interesting link: http://www.google.be/search?gcx=w&sourceid=chrome&ie=UTF-8&q=ArrayList+to+array

Waza_Be
  • 39,407
  • 49
  • 186
  • 260
1

String []strArray = new String[250];
arrList2.toArray(strArray);

CommonMan
  • 3,868
  • 2
  • 24
  • 35