Six Stars

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

  • Data Integration
Tags (2)
2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Manager

Re: Issue when trying to get the subtraction of two HashSets

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
Community Manager

Re: Issue when trying to get the subtraction of two HashSets

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

----------------------------------------------------------
Talend | Data Agility for Modern Business
5 REPLIES
Six Stars

Re: Issue when trying to get the subtraction of two HashSets

Can anybody advise? Appreciate it so much!

Community Manager

Re: Issue when trying to get the subtraction of two HashSets

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
Six Stars

Re: Issue when trying to get the subtraction of two HashSets

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!

Community Manager

Re: Issue when trying to get the subtraction of two HashSets

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

----------------------------------------------------------
Talend | Data Agility for Modern Business
Six Stars

Re: Issue when trying to get the subtraction of two HashSets

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.