object test2 { def main(args: Array[String]): Unit = { val im = scala.collection.immutable.Map(1->"one",2->"two") //不可变map val imh = scala.collection.immutable.HashMap(1->"one",2->"two") //不可变hashmap val mu = scala.collection.mutable.Map(1->"one",2->"two") //可变map println(im,manOf(im)) println(imh,manOf(imh)) println(mu,manOf(mu)) //mutable.Map to immutable.Map val mui = mu.toMap println(mui,manOf(mui)) //immutable.Map to mutable.Map val immu = scala.collection.mutable.Map(im.toSeq:_*) println(immu,manOf(immu)) val imhmu = scala.collection.mutable.Map(imh.toSeq:_*) println(imhmu,manOf(imhmu)) } //查看数据类型方法-manOf(data) def manOf[T:Manifest](t:T):Manifest[T]=manifest[T]} |
注意:
-.toSeq:将元组List转换成mutable.Map -:_*:表示变长参数 |
原文地址:https://www.cnblogs.com/xl717/p/11739177.html
时间: 2024-10-08 15:48:29