原创转载请注明出处:http://agilestyle.iteye.com/blog/2332525
Class hierarchy for Scala maps
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