java2db

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

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

Syntax:

 <specificCollectionObject>.retainAll(<specifiedCollectionElementsOblect>)

Example Code:

Execution Result:

Conclusion:

√ 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]



^ <