开发者

Understanding retainAll of Set- which is the specified set?

I'm having trouble understanding just how to use retainAll in Java. Its function is to create an intersection between sets A,B, where the resulting set has all the common elements between those two sets. And according to the Javadocs, retainAll()

Retains only the elements in this set that are contained in the specified 
collection (optional operation).  In other words, removes from this set 
all of its elements that are not contained 开发者_开发知识库in the specified collection

for sets A,B, a.retainAll(b), which is the specified collection? Is it the argument passed to the method? The textbook is not clear on this point.


The specified collection is B. "This set" is A, since it is the set that has the method on it. B is the other "specified collection".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜