How to compare 2 lists and return a new list with the missing values using ScriptRunner

Praveen July 19, 2017

I have 2 lists eg ListA[1,2,3,4] and ListB[2,3]. I need to compare both and create a new list with the values that are not found in ListB (i.e. ListC[1,4]).

1 answer

1 vote
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 19, 2017

You might try doing it like this:

def l1 = ["1", "2", "3", "4"]
def l2 = ["2", "3"]
def commons = l1.intersect(l2)
def difference = l1.plus(l2)
difference.removeAll(commons)
return difference

See image for result.

Screen Shot 2017-07-19 at 11.55.24 AM.png 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events