tJavaRow List to String conversion

One Star

tJavaRow List to String conversion

Hi,
I have a tJavaRow with the line of code below:
myarray = ((java.util.List<String>)globalMap.get("input_row.ReturnValue")).toArray();
But I get the error:
Type mismatch: cannot convert from Object[] to String[]
input_row.ReturnValue is type List and myarray is initialised as type array. What would be the correct syntaxt to return myarray as an array?

Your help much appreciated.
Thanks.
One Star

Re: tJavaRow List to String conversion

Add "new String" as a parameter to the toArray() method. This block of code demonstrates
		String[] sodas = null;

List<String> sodaList = new ArrayList<String>();

sodaList.add("coke");
sodaList.add("pepsi");
sodaList.add("7-up");

sodas = sodaList.toArray(new String);
for( String s : sodas ) {
System.out.println(s);
}
One Star

Re: tJavaRow List to String conversion

Thanks for your help.
I pasted in the code you sent after trying to modify mine to work but to no avail.
I get the error: ArrayList cannot be resolved to a type. Can you assist?
===
String[] sodas = null;

List<String> sodaList = new ArrayList<String>();

sodaList.add("coke");
sodaList.add("pepsi");

sodas = sodaList.toArray(new String);
===
One Star

Re: tJavaRow List to String conversion

You'll need to import java.util.List and java.util.ArrayList. In the tJavaRow Advanced Settings, add the following to the code editor
import java.util.List;
import java.util.ArrayList;
One Star

Re: tJavaRow List to String conversion

Excellent!!! - much appreciated.......
Thanks for your help. :-)