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

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

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
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

1,030 views 4 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you