How to compare two String Lists and spit out the differences, put them in a String Lists - SOLVED

Hi All,

I want to compare two String Lists and spit out the differences, put them in a String Lists.

For Eg.,
ListA
Micheal
Jackson
Katy
Perry
Ne-Yo
Guetta
Eminem
Linkinpark and so on…

ListB
Micheal
Justin
Katy
Perry
Ne-Yo
Linkinpark and so on…

I want the difference in two String Lists say (ListC and ListD)

***Items from first list that are not in second list
Jackson
Eminem
Guetta

***Items from second list that are not in first list
Justin

Do we have a BIS for this in wM 8.x and above or should we write a custom java/flow service.

Please provide your inputs/comments on this.

There is no BIS for this, you can go for a flow service…if you are comparing based on certain patterns or regular expressions go for a java service.

@ Sreenivas,

Writing the same logic using LOOP will not be feasible due to performance issues.

Can you share your ideas/comments. I have a sample java code but I should adapt the same code to suit webMethods 7.1.2 API

If performance is important you can do this in java using collections and ListUtils.

@ Anjni,
Yes. I am aware of that. Currently i am working on the java code that I downloaded for Google.

Do you have a working code with you? please share :slight_smile:

Did u try something like this
String[] A = {“Michael”, “Joe”, “Katy”};
String[] A = {“Michael”, “Joe”, “Justin”};
List finalDiff = ListUtils.subtract(Arrays.asList(A), Arrays.asList(B));

ListUtils is a class available in apache commons jar
see this http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/ListUtils.html

Hi Mahesh,
The Tundra package has a lot of unique utilities and one of them does exactly what you need.

Tech Community post:
http://techcommunity.softwareag.com/ecosystem/communities/public/f2146ca4-ad80-11e2-8369-cd8d7ef22065/

Download the Tundra package from GIT:
https://github.com/Permafrost/Tundra

Then look for the service within the Tundra package:
tundra.list.string:difference

Cheers,
David

1 Like

Thanks… I will check and get back to you!