Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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

Dillinger4

Dazed Member
Joined
Oct 13, 1999
Messages
3,418
Two methods are needed in this case.
Code:
boolean containsAll(Collection<?> c)
boolean disjoint(Collection<?>c1 Collection<?>c2)
Since containsAll(Collection<?> c) 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).
 
Last edited:
Top