One Star

[resolved] how to iterate through ArrayList?

Hi,
I have an ArrayList I set in a tJavaFlex component
globalMap.put("list",list);
I can read the "global" value ie:
(java.util.List)globalMap.get("list")
I wander how I can iterate through x, y, then z, based on (java.util.List)globalMap.get("list")
iteration?
thanks in advance for any help.
JNB
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] how to iterate through ArrayList?

Hello
You can aslo use tLoop to iterate each value of list. see my screenshots.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
7 REPLIES
One Star

Re: [resolved] how to iterate through ArrayList?

I managed to iterate the list values that way
In a tJava component
Object ia[] = ((java.util.List<String>)globalMap.get("list")).toArray();
for(int k=0; k<ia.length; k++) {
context.val = context.val + ia + ";";
}
Then I can process
tFixedFlowInput->tNormalize ... and iterate through each value of my initial arrayList.
I'm not sure it's the best way to do it but that works.
JNB
Community Manager

Re: [resolved] how to iterate through ArrayList?

Hello
You can aslo use tLoop to iterate each value of list. see my screenshots.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] how to iterate through ArrayList?

Hi. This is similar to the scenario I am trying to develop, except instead of a tJava component, I want to feed each element of the List into a tMap. How do I arrange this? Can't seem to get the flows right to get myself access into the tMap.
i.e. something like
tLoop => . . . => tMap (for each element)
Thanks!
Community Manager

Re: [resolved] how to iterate through ArrayList?

Hi. This is similar to the scenario I am trying to develop, except instead of a tJava component, I want to feed each element of the List into a tMap. How do I arrange this? Can't seem to get the flows right to get myself access into the tMap.
i.e. something like
tLoop => . . . => tMap (for each element)
Thanks!

Hi
I am sure the code in tJava should also work in tMap, if you can't get the job work, please upload a screenshot of job.

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] how to iterate through ArrayList?

Apologies for the late response; thanks Shong for your reply. It all worked out as you suggested. Smiley Happy
One Star

Re: [resolved] how to iterate through ArrayList?

Hi
I have scenario to iterate through Arraylist .I have list of customercode where i should check the custcode with the table if it exist it should go to the if condition there i m creating a temporary table to do bulk updation,if it doesn't exist it has to go to else part.
how can i solve this issue? i am facing problem while iterating a list.
Fifteen Stars

Re: [resolved] how to iterate through ArrayList?

This tutorial might help. It was written to demonstrate how to replicate the "Connect By" Oracle functionality in Talend. But the first component receives data as an ArrayList and iterates through the list using a tJavaFlex. Take a look (https://www.rilhia.com/tutorials/talend-connect-example).
Rilhia Solutions