package num01
import scala.collection.convert.AsScalaConverters
import scala.collection.JavaConverters.
import scala.collection.mutable.Map
object scala_for_impatient {
def main(args: Array[String]): Unit = {
val scores0 = Map("Alice" -> 10,"Bob" -> 3,"Cindy" -> 8)
val scores1 = scala.collection.mutable.Map("Alice" -> 10,"Bob" -> 3,"Cindy" -> 8)
val scores2 = new scala.collection.mutable.HashMap[String,Int]()
val bobscore = scores0("Bob")
val bobscore0 = scores0.getOrElse("Bob",0)
scores1("Bob")=10
scores2 += ("Bob" -> 10,"Fred"->17)
scores2 -= "Alice"
val newScores = scores0 + ("Bob" -> 10,"Fred"->17)
scores0.keySet/*返回键集合*/
for (v <- scores0.values)println(v)/*返回值序列*/
for ((k,v) <- scores0)yield (v,k)/*交换键值位置*/
val scores4 = scala.collection.mutable.SortedMap("Alice" -> 10,"Bob" -> 3,"Cindy" -> 8)
/*利用java定义可变树形映射,指定scala映射类型出发转换*/
/*val scores:scala.collection.mutable.Map[String,Int]=new java.util.TreeMap[String,Int]*/
/*元组是不同类型的值得聚集*/
val t = (1,1.34,"Fred")/*类型为Tuple[Int,Double,java.lang.String]*/
val second =t._2 /*将second设为3.14*/
val (first, _, third) = t/*在不需要的部件上面用_代替*/
"New York".partition(_.isUpper)/*返回满足条件和不满足条件的字符*/
/*拉链操作:使用元组的原因之一就是把多个值绑在一起处理*/
val symbols = Array("<","-",">")
val counts = Array(2,10,2)
val pairs = symbols.zip(counts)
for((s,n) <- pairs)Console.print(s*n)
}
}