Using disjoint() from the standard Java Collections utilities can determine if the two collections contain any common elements. If collections are not disjoint, then they contain at least one common element.
Internally, Collections.disjoint() checks to see if any collection is Set , and optimizes accordingly.
import collection.JavaConverters._ val a = List(1,2,3,4,5,6,7) val b = List(11,22,33,44,55,6) !java.util.Collections.disjoint(a.asJava, b.asJava)
Although it still converts the Scala collection into a Java collection. On the other hand, the additional Apache Commons library is not needed.
source share