Remove all spin json list of elements from another spin json list


#1

Hi Guys,

I am trying to remove list of spin json list elements from another spin json list , but it is not working and removeAll method is returning false, hw can I make it happen, below is my code:

SpinJsonNode spinJson1 = Spin.JSON("[{“age”:25},{“age”:28},{“age”:24}]");
SpinJsonNode spinJson2 = Spin.JSON("[{“age”:25},{“age”:28}]");
System.out.println(">>>>>>"+spinJson1.elements().removeAll(spinJson2.elements()));
System.out.println("…"+spinJson1);

Finally spinJson1 return complete list of elements which does not remove anything


#2

See below post by @thorben

So you can use

spinJson1.remove(obj);

to remove a specific object

or

spinJson1.removeAt(index);

to remove element at a specific index.

or simply assign it to an empty array to clear all elements

In your case, you could iterate on elements of the second list and do

spinJson1.remove(obj);
on each object


#3

Hi Hassan,

thanks for reply but is there no other way to remove the list at once instead of looping over, i need to keep the code minimum on modeler .


#4

I don’t think there is a way to do it in one call…