快学Scala上讲解,优点繁琐。 应用数组的差集简单很多。
scala> val arr = Array(1,2,3,4,5,-1,6,-2,7,-3,8,-4,9,-5)
arr: Array[Int] = Array(1, 2, 3, 4, 5, -1, 6, -2, 7, -3, 8, -4, 9, -5)
scala> val r = arr.filter(_ < 0)
r: Array[Int] = Array(-1, -2, -3, -4, -5)
scala> arr.diff(r.tail)
res0: Array[Int] = Array(1, 2, 3, 4, 5, -1, 6, 7, 8, 9)
转载于:https://blog.51cto.com/12211918/2066653