How to check if collection contains any element from other collection in Scala?
You can use a combination of exists(p: T => Boolean):Boolean
and contains(elem: A1):Boolean
:
val a = List(1,2,3,4,5,6,7)
val b = List(11,22,33,44,55,6)
a.exists(b.contains) // true
Intersect
val a = Seq(1,2,3) ; val b = Seq(2,4,5)
a.intersect(b)
res0: Seq[Int] = List(2)
// to include the test:
a.intersect(b).nonEmpty // credit @Lukasz