Scala Mutable SortedMap drop() 方法与示例
drop()方法用于删除前“n”个元素。
Method Definition: def drop(n: Int): SortedMap[A, B]
Return Type: It returns all the elements of the SortedMap except the first ‘n’ elements.
示例 #1:
// Scala program of drop()
// method
import scala.collection.SortedMap
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedMap
val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 5)
// Applying drop method
val result = m1.drop(1)
// Displays output
println(result)
}
}
输出:
Map(for -> 3, geeks -> 5)
示例 #2:
// Scala program of drop()
// method
import scala.collection.SortedMap
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedMap
val m1 = SortedMap("geeks" -> 5, "for" -> 3, "geeks" -> 5)
// Applying drop method
val result = m1.drop(1)
// Displays output
println(result)
}
}
输出:
Map(geeks -> 5)
因此,两个相同的键都从 SortedMap 中删除。