Scala Mutable SortedSet dropWhile()
在 Scala 可变集合中,使用 dropWhile()方法从 SortedSet 中删除满足规定条件的元素的最长前缀。
Method Definition: def dropWhile(p: (A) => Boolean): SortedSet[A]
Return Type: It returns a TreeSet containing all the elements after dropping the longest prefix of elements from the SortedSet that satisfies the stated condition.
示例 #1:
// Scala program of dropWhile()
// method
import scala.collection.mutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
var s1 = SortedSet(1, 3, 5, 4, 2)
// Print the SortedSet
println(s1)
// Applying dropWhile method
var res = s1.dropWhile(x => {x % 2 != 0})
// Displays output
println(res)
}
}
输出:
TreeSet(1, 2, 3, 4, 5)
TreeSet(2, 3, 4, 5)
示例 #2:
// Scala program of dropWhile()
// method
import scala.collection.mutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
var s1 = SortedSet(15, 17, 21)
// Print the SortedSet
println(s1)
// Applying dropWhile method
var res = s1.dropWhile(x => {x % 3 == 0})
// Displays output
println(res)
}
}
输出:
TreeSet(15, 17, 21)
TreeSet(17, 21)