Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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.
Labels (3)
5 Replies
Anonymous
Not applicable
Author

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);
}
Anonymous
Not applicable
Author

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);
===
Anonymous
Not applicable
Author

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;
Anonymous
Not applicable
Author

Excellent!!! - much appreciated.......
Thanks for your help. 🙂
Anonymous
Not applicable
Author

You can also try using out to TjavaRow then:

Create Contex  (Context.Your_context_Name)

** content  is the object the coming from row1 **

 

Context.Your_context_Name = String.valueOf(row1.content);

Then you can check with print: System.out.print("The string from object is: +Context.Your_context_Name);