首页 > 代码库 > Scala Set的一些用法
Scala Set的一些用法
scala> val set = Set(3,2,4,8,1) set: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 8, 4) scala> set.min res58: Int = 1 scala> set.max res59: Int = 8 scala> set.size res60: Int = 5 scala> val set1 = Set(9,8) set1: scala.collection.immutable.Set[Int] = Set(9, 8) scala> set & set1 res63: scala.collection.immutable.Set[Int] = Set(8) scala> set.intersect(set1) res65: scala.collection.immutable.Set[Int] = Set(8) scala> set ++ set1 res66: scala.collection.immutable.Set[Int] = Set(1, 9, 2, 3, 8, 4) scala> set -- set1 res67: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4) scala> set &~ set1 res68: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4) scala> set1.count(_ > 5) res70: Int = 2 scala> set.diff(set1) res71: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4) scala> set1.diff(set) res72: scala.collection.immutable.Set[Int] = Set(9) scala> set.slice(1,4) res83: scala.collection.immutable.Set[Int] = Set(2, 3, 8) scala> set.subsets(2).foreach(x=>println(x)) Set(1, 2) Set(1, 3) Set(1, 8) Set(1, 4) Set(2, 3) Set(2, 8) Set(2, 4) Set(3, 8) Set(3, 4) Set(8, 4)
Scala Set的一些用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。