How to convert ‘ArrayList to String array in Java
Using Collection.toArray method First way to convert arraylist is to use built-in for every java collection method toArray(T[] ts) For example:
1 2 3 4 5 6 |
List<String> animals = new ArrayList<String>(); //add some elements animals.add("cat"); animals.add("dog"); String[] stringArray = animals.toArray(new String[0]); System.out.println(Arrays.toString(stringArray)); |
The toArray() method without any argument returns Object[]. So you have …
Read More