带有示例的 Scala BitSet dropWhile() 方法
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 drop() 方法用于删除满足谓词的元素的最长前缀。
Method Definition: def drop()
Return Type: It returns the longest suffix of collection whose first element does not satisfy p.
示例 #1:
// Scala program of dropWhile()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
var s1 = BitSet(1, 3, 5, 4, 2)
// Print the BitSet
println(s1)
// Applying dropWhile method
var res = s1.dropWhile(x => {x % 2 != 0})
// Displays output
println(res)
}
}
输出:
BitSet(1, 2, 3, 4, 5)
BitSet(2, 3, 4, 5)
示例 #2:
// Scala program of dropWhile()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
var s1 = BitSet(15, 17, 21)
// Print the BitSet
println(s1)
// Applying dropWhile method
var res = s1.dropWhile(x => {x % 3 == 0})
// Displays output
println(res)
}
}
输出:
BitSet(15, 17, 21)
BitSet(17, 21)