How to get the difference between two arrays in Scala

1 Answer

0 votes
object SetDifference {
  def main(args: Array[String]): Unit = {
    val array1 = Array("c#", "c", "c++", "java", "python", "vb", "scala")
    val array2 = Array("rust", "c", "c++", "go", "python", "nodejs")

    val set1 = array1.toSet
    val result = array2.filterNot(set1.contains)

    println(result.mkString(" "))
  }
}

   
   
/*
run:

rust go nodejs
 
*/

 



answered Feb 5, 2025 by avibootz

Related questions

...