I have a ArrayList that contains values in the form [ann,john]. I want to convert this ArrayList into a String array in the form {\"ann\",\"john\"}.
How should I do
Well in general:
List<String> names = new ArrayList<String>();
names.add("john");
names.add("ann");
String[] namesArr = new String[names.size()];
for (int i = 0; i < names.size(); i++) {
namesArr[i] = names.get(i);
}
Or better yet, using built in:
List<String> names = new ArrayList<String>();
String[] namesArr = names.toArray(new String[names.size()]);