代码之家  ›  专栏  ›  技术社区  ›  Jason

了解集合的retinall-哪一个是指定的集合?

  •  2
  • Jason  · 技术社区  · 14 年前

    我很难理解如何在Java中使用retainal。它的功能是在集合A、B之间创建一个交集,其中结果集合在这两个集合之间具有所有公共元素。根据Javadocs,retainal()

    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
    

    对于A、B组, a.retainAll(b) ,哪个是指定的集合?是传递给方法的参数吗?教科书对这一点不清楚。

    1 回复  |  直到 14 年前
        1
  •  3
  •   YWE    14 年前

    指定的集合是B。“此集合”是A,因为它是具有方法的集合。B是另一个“指定集合”。