Skip to content

Instantly share code, notes, and snippets.

@xtea
Created September 2, 2015 10:54
Show Gist options
  • Save xtea/6194d799fe5338631811 to your computer and use it in GitHub Desktop.
Save xtea/6194d799fe5338631811 to your computer and use it in GitHub Desktop.
Collection convert to array in java
import java.util.ArrayList;
import java.util.Collection;
public class CollectionToArray {
public static void main(String[] args) {
Collection<String> collection = new ArrayList<String>();
collection.add("jack");
collection.add("john");
collection.add("jason");
String[] array = new String[collection.size()];
collection.toArray(array);
System.out.println(array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment