YouTip LogoYouTip

Collection Conversion

# Java Example - Collection to Array [![Image 3: Java Examples](#) Java Examples](#) The following example demonstrates how to use the `list.add()` and `list.toArray()` methods of the Java Util class to convert a collection to an array: ## Main.java File ```java import java.util.*; public class Main{ public static void main(String[]args){ Listlist = new ArrayList(); list.add("Rookie"); list.add("Bird"); list.add("Teach"); list.add("Program"); list.add("www..com"); String[]s1 = list.toArray(new String); for(int i = 0; i<s1.length; ++i){ String contents = s1; System.out.print(contents); } } } Running the above code produces the following output: www..com [![Image 4: Java Examples](#) Java Examples](#)
← Thread ShowallThread Id β†’