Issue
In my pipeline, I have two lists and want to compare it and print output accordingly
1- println abc
[aaa, bbb, ccc]
2- println xyz
[bbb, ccc]
I need to print the output to a file like:
aaa not present in xyz
bbb present
ccc preset
Code I tried:
def test []
test = abc - xyz
println test
Solution
def abc = ['aaa', 'bbb', 'ccc']
def xyz = ['bbb', 'ccc']
//simple
println 'present in xyz: ' + abc.intersect(xyz).join(', ')
println 'not present in xyz: ' + abc.minus(xyz).join(', ')
//with for-each
for(i in abc){
if(i in xyz) println "present in xyz: $i"
else println "not present in xyz: $i"
}
Answered By - daggett
Answer Checked By - Mildred Charles (JavaFixing Admin)