PDA

Click to See Complete Forum and Search --> : Java - Two Collections. The same elements or have no elements in common


Dillinger4
Sep 29th, 2005, 10:36 AM
Two methods are needed in this case.

boolean containsAll(Collection<?> c)
boolean disjoint(Collection<?>c1 Collection<?>c2)

Since containsAll(Collection<?> c)[i] is defined within the [i]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).