Forum Discussion

bpet's avatar
bpet
New Contributor
5 years ago

How to compare two Array Lists in SoapUI using groovy script?

I have 2 lists, the first one I got from json response when collecting all the customer numbers, the second one from a database using a query that should give me the same customer numbers as the response to the rest request. 

listA = [0012345678, 0012123443, 0012321232, 0055544321]

listB = [0012123443, 0012321232, 0055544321, 0012345678]

 

I want to check if both of the lists contain the same items.

I don't care about the order, just if they have the exact same items.

I tried listA.contains(listB), listA.containsAll(listB), i tried sorting both the lists (listA.sort() and listB.sort()) and then used equals, I still get false. It doesn't even seem to really sort the values, I thought this would work considering they are numbers, or at least appear so.

There is no difference in number of white spaces between the numbers in both lists.

Any suggestions?

 

1 Reply

  • avidCoder's avatar
    avidCoder
    Super Contributor

    This code will take out the common b/w two lists:-

     

    ArrayList<String> listOne = new ArrayList<>(Arrays.asList('0012345678', '0012123443', '0012321232', '65', '2324'));      
    ArrayList<String> listTwo = new ArrayList<>(Arrays.asList('0012123443', '0012321232', '0055544321', '342', '3423'));
    listOne.retainAll(listTwo);
    log.info listOne