📜  Scala Map 迭代器方法与示例

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

Scala Map 迭代器方法与示例

迭代器方法用于给出一个迭代器。

示例 #1:

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

示例 #2:

// Scala program of iterator
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a map
        val m1 = Map() 
          
        // Applying iterator method
        val result = m1.iterator
          
        // Displays output
        println(result)
      
    }
}
输出:
empty iterator