diff()方法用于计算一组和另一组的差。
函数定义: def diff(that: Set[A]): Set[A]
返回类型: It returns a set which is the difference between two sets.
范例1:
// Scala program of diff()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating sets
val s1 = Set(1, 2, 3, 4, 5)
val s2 = Set(1, 2, 3)
// Applying diff method
val s3 = s1.diff(s2)
// Displays output
for(elem <- s3)
println(elem)
}
}
输出:
5 4
范例2:
// Scala program of diff()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating sets
val s1 = Set(1, 2, 3, 4, 5)
val s2 = Set(6, 2, 7, 8)
// Applying diff method
val s3 = s1.diff(s2)
// Displays output
for(elem <- s3)
println(elem)
}
}
输出:
5 1 3 4
相关用法
- Scala TreeSet diff()用法及代码示例
- Scala Stack diff()用法及代码示例
- Scala SortedSet diff()用法及代码示例
- Scala Queue diff()用法及代码示例
- Scala Map take()用法及代码示例
- Scala Set max()用法及代码示例
- Scala Map get()用法及代码示例
- Scala Set min()用法及代码示例
- Scala Int until(end: Int)用法及代码示例
- Scala Set take()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 Scala Set diff() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。