I have problem in the following code:

It is a code to parse a tree node with any number of childs

Code:
// generate a collection to hold the children
Collection<TreeNode<String>> children = new ArrayList<TreeNode<String>>();
 
while (has more child){
	children.add(parse the child...);
}
 
createNode(...);
Now there is a problem, createNode takes an array if TreeNode<String> instead of collection.
Now I am stuck between array and collection
toArray returns Object[] which i cannot cast to TreeNode<String>[]
I also cannot create a new TreeNode<String> array and copy the values into the array (ie: TreeNode<String>[] nodes = new TreeNode<String>[size]; does not work)

What can I do here?