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

Issue when trying to get the subtraction of two HashSets

Hi All,

The following is my scenario:

 

Set<String> cs = new HashSet<>();

cs.add(row5.c);

globalMap.put("cSet",cs);

 

Set<String> tcs = new HashSet<>();

cs.add(row5.tc);

globalMap.put("tcSet",tcs);

 

Set<String> Bn = new HashSet<>();
Bn.addAll((Set<String>)globalMap.get("cSet"));
Bn.removeAll((Set<String>)globalMap.get("tcSet"));

 

 

ERROR MESSAGE:

Exception in component tJava_2
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Set

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi
I tested your code with a simple job, but I don't have compilation error.
tFixedFlowInput--main--tJava
Can you explain why you need to write Java code? Please give us more detailed information about your requirement, maybe you can achieve it with existing components.

Regards
Shong

View solution in original post

5 Replies
Anonymous
Not applicable
Author

Can anybody advise? Appreciate it so much!

Anonymous
Not applicable
Author

Hi
I tested your code with a simple job, but I don't have compilation error.
tFixedFlowInput--main--tJava
Can you explain why you need to write Java code? Please give us more detailed information about your requirement, maybe you can achieve it with existing components.

Regards
Shong
Anonymous
Not applicable
Author

Thanks for your reply, Shong.

 

What I want is to get the difference in those two sets. I define those two sets first and then use addAll() and removeAll() method to accomplish it, but it failed with errors. Appreciate your help!

Anonymous
Not applicable
Author

Hi

I tested your code and it works without error, would you mind uploading your job or sending it to me via email? I will look into it further.

Regards

Shong

Anonymous
Not applicable
Author

Thanks for your help, Shong. I just added an output following my scripts which is System.out.println(Bn), then I got what I want, thanks for your answers.