ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
```scala object HelloWorld { def main(args: Array[String]): Unit = { var s = Set("ab", "yz") // ab yz // 注意:对于所有不可变集合来说,如 s += "mn" 操作其实是创建了一个新的Set集合,如果使用 val声明s的话是会报错的 s += "mn" // mn, ab, yz s += "mn" // mn, ab, yz s -= "yz" // mn, ab var t = Set("ab", "gh", "mn", "st", "yz") // 求差集 var c1 = t -- s // gh, st, yz // 求并集 var c2 = t ++ s // ab, gh, mn, st, ya import scala.collection.mutable._ var os = SortedSet(1, 99, 66, 54, 77) os //1, 54, 66, 77, 99 os += 33 os //1, 33, 54, 66, 7 var s2 = Set("ab", "yz") var t2 = Set("ab", "gh", "mn", "st", "yz") //求交集 var s3 = t2 & s2 var s4 = t2 intersect s2 println(s3) // Set(yz, ab) //求并集 var s5 = t2 | s2 var s6 = t2 union s2 println(s5) // Set(yz, ab, gh, mn, st) //求差集 var s7 = t2 &~ s2 var s8 = t2 diff s2 println(s7) // Set(gh, mn, st) } } ```