Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
c | collection containing elements to be retained in this collection |
UnsupportedOperationException | if the retainAll operation is not supported by this collection | |
ClassCastException | if the types of one or more elements in this collection are incompatible with the specified collection (optional) | |
NullPointerException | if this collection contains one or more null elements and the specified collection does not permit null elements (optional), or if the specified collection is null |
remove(Object), contains(Object)
Diagram: Collection List