Notes
In Apex, retainAll(setOfElementsToRetain)
method retains only the elements in the original set that are contained in the specified set.
Here's an Example:
Set<String> stringSet = new Set<String>{'apple', 'banana', 'cherry', 'orange'};
Set<String> elementsToRetain = new Set<String>{'apple', 'orange'};
stringSet.retainAll(elementsToRetain);
System.debug('Set after retaining elements: ' + stringSet);
Output: Set after retaining elements: {apple, orange}
Video
Video does not exists.