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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Iterate through HashMap

Hi Friends,

 

The following is my scenario,

 

Map<String, HashSet<String>> iB = new HashMap<String, HashSet<String>>();

if(!iB.containsKey(row5.i)){
iB.put(row5.i,new HashSet<String>());
}
iB.get(row5.i).add(row5.c);

globalMap.put("iBMap", iB);

 

for(String i:globalMap.get("iBMap".keySet())){

row10.issue = i;
StringBuilder sb = new StringBuilder();
for(String c : globalMap.get("iBMap").get(i)) {
sb.append("'").append(cusip).append("'").append(",");
row10.color=c;
}

}

 

Can anyone give some opinions that the reason why this can't go through?

 

Thanks!!

Labels (3)
1 Solution

Accepted Solutions
cterenzi
Specialist
Specialist

You should also give us a hint as to your job structure and any error messages.

 

Just from looking at your code, you're not casting your globalMap.get() results to the appropriate type.  The get() method returns type Object, so you should cast to the right type if you want to use applicable methods.

 

You also need to get the object before you can operate on it.  This means globalMap.get("iBMap".keySet()) won't work, but (Map)globalMap.get("iBMap").keySet() should.

 

Also, since you appear to be using a custom code component, you should get() iBMap once, operate on the local object, and then put() it when finished to save changes. (i.e. assign (Map)globalMap.get("iBMap") to a local variable and loop over it, retrieving keys and values from it rather than constantly getting the object from globalMap).

 

All that said, this type of setup doesn't really leverage Talend's strengths.  With a more general explanation of your use case, we may be able to suggest an approach that doesn't involve custom Java code.

View solution in original post

5 Replies
TRF
Champion II
Champion II

What do you expect?
Anonymous
Not applicable
Author

Thanks for your reply, TRF.

 

My expectation is passing the value of HashMap(In my case it's a HashSet) to row10..

TRF
Champion II
Champion II

You should try to expose your use case with sample data and expected result.
cterenzi
Specialist
Specialist

You should also give us a hint as to your job structure and any error messages.

 

Just from looking at your code, you're not casting your globalMap.get() results to the appropriate type.  The get() method returns type Object, so you should cast to the right type if you want to use applicable methods.

 

You also need to get the object before you can operate on it.  This means globalMap.get("iBMap".keySet()) won't work, but (Map)globalMap.get("iBMap").keySet() should.

 

Also, since you appear to be using a custom code component, you should get() iBMap once, operate on the local object, and then put() it when finished to save changes. (i.e. assign (Map)globalMap.get("iBMap") to a local variable and loop over it, retrieving keys and values from it rather than constantly getting the object from globalMap).

 

All that said, this type of setup doesn't really leverage Talend's strengths.  With a more general explanation of your use case, we may be able to suggest an approach that doesn't involve custom Java code.

Anonymous
Not applicable
Author

Thanks so much, it works!