📜  Scala Map drop() 方法与示例

📅  最后修改于: 2022-05-13 01:54:23.154000             🧑  作者: Mango

Scala Map drop() 方法与示例

drop()方法用于删除前“n”个元素。

示例 #1:

// Scala program of drop()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a map
        val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 5)
          
        // Applying drop method
        val result = m1.drop(1)
          
        // Displays output
        println(result)
      
    }
}
输出:
Map(for -> 3, cs -> 5)

示例 #2:

// Scala program of drop()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a map
        val m1 = Map("geeks" -> 5, "for" -> 3, "geeks" -> 5)
          
        // Applying drop method
        val result = m1.drop(1)
          
        // Displays output
        println(result)
      
    }
}
输出:
Map(for -> 3)

因此,两个相同的键都从地图中删除。