The following example demonstrates how to use the list.add() and list.toArray() methods of the Java Util class to convert a collection into an array:
/* author by w3cschool.cc Main.java */ import java.util.*; public class Main{ public static void main(String[] args){ List<String> list = new ArrayList<String>(); list.add("菜"); list.add("鸟"); list.add("教"); list.add("程"); list.add("www.w3cschool.cc"); String[] s1 = list.toArray(new String[0]); for(int i = 0; i < s1.length; ++i){ String contents = s1[i]; System.out.print(contents); } } }
The output of the above code is: :
菜鸟教程www.w3cschool.cc
The above is the Java example - the content of converting a collection to an array. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!