Results 1 to 1 of 1

Thread: Java - Two Collections. The same elements or have no elements in common

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Java - Two Collections. The same elements or have no elements in common

    Two methods are needed in this case.
    Code:
    boolean containsAll(Collection<?> c)
    boolean disjoint(Collection<?>c1 Collection<?>c2)
    Since [i]containsAll(Collection<?> c)[i] is defined within the Collection interface all concrete implementations will be able to use this method. disjoint(Collection<?>c1 Collection<?>c2) is defined within the Collections class.

    Using both of these methods is pretty straight forward. containsAll(Collection<?> c) is an instance method so naturally it must be invoked on an object. disjoint(Collection<?>c1 Collection<?>c2) is defined as Static within the Collections class so all that is needed is to invoke it using the class name ie Collections.disjoint(Collection<?>c1 Collection<?>c2).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width