BoxSetRetainAll
Retain only the elements of a Set that are also present in the given collection, removing everything else.
This is the in-place equivalent of computing an intersection. The Set is modified in place and returned to support method chaining.
Method Signature
BoxSetRetainAll(set=[modifiableSet], values=[any])Arguments
Argument
Type
Required
Description
Default
set
modifiableSet
true
The set to filter in place.
values
any
true
The collection whose membership determines which elements are kept. Accepts an Array, Set, list-delimited String, or any castable collection.
Examples
Keep only elements that are also in another collection
Elements NOT present in the argument collection are removed.
s = [ 1, 2, 3, 4, 5 ].toSet();
s.retainAll( [ 3, 4, 999 ] );
writeOutput( s.size() );
Result: 2
Intersect a Set in-place
Result: 2
Related
Last updated
Was this helpful?
