Disclosure: This text could comprise affiliate hyperlinks. Once you buy, we could earn a fee.
Tips on how to convert String ArrayList to Array in Java? Instance
Right here is full code instance of Java check program which convert String ArrayList to String Array in Java. On this Java program we first create an ArrayList which shops identify of month in String format after which we convert that into an String array.
Java Program to transform an ArrayList of String to an Array
import java.util.ArrayList;
import java.util.Arrays;
public class ArrayListtoArray {
public static void predominant(String args[]){
//ArrayList containing string objects
ArrayList<String> aListMonth
= new ArrayList<String>();
aListMonth.add(“Jan”);
aListMonth.add(“Feb”);
aListMonth.add(“mar”);
/*
* To transform ArrayList containing String parts to String array, use
* Object[] toArray() methodology of ArrayList class.
*/
//First Step: convert ArrayList to an Object array.
Object[] objMnt = aListMonth.toArray();
//Second Step: convert Object array to String array
String[] strMnts = Arrays.copyOf(objMnt, objMnt.size, String[].class);
System.out.println(“ArrayList transformed to String array”);
//print parts of String array
for(int i=0; i < strMnts.size; i++){
System.out.println(strMnts[i]);
}
}
}

Record of Java homework train program from java67 weblog