原创转载请注明出处:http://agilestyle.iteye.com/blog/2332525

 

Class hierarchy for Scala maps

Scala Map

 

package org.fool.scala.basic

import scala.collection.mutable

object ScalaMap {
  def main(args: Array[String]): Unit = {
    val treasureMap = mutable.Map[Int, String]()
    treasureMap += (1 -> "Go to island.")
    treasureMap += (2 -> "Find big X on ground.")
    treasureMap += (3 -> "Dig.")
    println(treasureMap(2))

    val ages = Map("Hadoop" -> 8, "Spark" -> 3)

    for ((k, v) <- ages) {
      println("Key is " + k + ", value is " + v)
    }

    for ((k, _) <- ages) {
      println("Key is " + k)
    }

    for ((_, v) <- ages) {
      println("Value is " + v)
    }

  }
}

Console Output

Scala Map
 

 

 

相关文章:

  • 2021-11-02
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-09-08
  • 2021-09-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-06-03
  • 2021-06-30
相关资源
相似解决方案