retainAll method in Collections framework

retainAll method will retains the collection(List,Set,Vector,Collection) elements  that are contained in the specified collection of elements,retainAll method is opposite to removeAll method

Add elements to collection and pass it to retainAll method as an argument
Returns true if elements retains in specific collection else returns false



Example Code:

Execution Result:


√ Retains one or more elements in specific collection,if  it equals to the specified collection elements.
It is an optional operation.

Related Posts :
addAll method in java Collections
containsAll method in Collections framework
toArray method in Collections framework
   [will not be published]

^ <