Scala BitSet dropRight() 方法及实例
Scala 的 Bitsets 是非负整数的集合,它们被表示为打包到 64 位字中的位变长数组。drop() 方法用于选择除 n 个项之外的所有元素。
方法定义:def drop()
返回类型:返回一个可遍历的集合,但不包括 n 个项
示例 #1:
// Scala program of drop()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating BitSet
val s1 = BitSet(1, 2, 3, 4, 5)
// Applying dropRight method
val s2 = s1.dropRight(2)
// Displays output
for(elem <- s2)
println(elem)
}
}
1
2
3
示例 #2:
// Scala program of drop()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating BitSet
val s1 = BitSet(1, 2, 3, 7, 9, 4, 5)
// Applying dropRight method
val s2 = s1.dropRight(3)
// Displays output
for(elem <- s2)
println(elem)
}
}
“`scala
1
2
3
4
“`**更多Scala相关文章,请阅读:[Scala 教程](https://geek-docs.com/scala)**