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
See below post by @thorben
Hi Maria,
whenever Spin gives you a java.util.List, this is a copy of a collection of elements, not a view on that element collection in the original datastructure. So modifying the list will not do anything more than that.
See the following link for how to add an element to a JSON array and other examples:
Cheers,
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
1 Like
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 .
I don’t think there is a way to do it in one call…