Scala 中 set 的实战应用 :图书管理系统
package T_11_6
import scala.collection.mutable
object MS {
def main(args: Array[String]): Unit = {
//1.
val books =mutable.Set("朝花惜拾","活着")
println(books)
// 2.
books += "100万个为什么"
books += "十二木卡姆"
println(books)
//3 .
books -= "活着"
println(books)
//4.
val b1 = books.contains("python从入门到实践")
println(s"python从入门到实践这本书是否存在:${b1}")
//5.
val books2 = Set("100万个为什么","朝花惜拾","口才培养","普通话口训")
//6.
val s1 =books.union(books2)
println("两个图书馆集合的并集",s1)
//7.
val s2 = books.intersect(books2)
println("两个图书馆集合的交集", s2)
//8.
val s3 = books2.diff(books)
println("当前图书馆相对于另一个图书馆的差集", s3)
}
}
原文地址:https://blog.csdn.net/a1199a/article/details/143574740
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!