原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-38/

There I am,in the world more exciting!

www.ptbird.cn


package com.ptbird.scala import scala.collection.immutable.{TreeMap, TreeSet} import scala.collection.mutable /** * Created by postbird on 2016/5/26. */ object SetMapTreeSetMapTest { def main(args: Array[String]): Unit = { val data = mutable.Set.empty[Int] data ++= List(1, 2, 3) data += 4 data --= List(2, 3) println(data) // Set(1, 4) data += 1 println(data) //Set(1, 4) /** * set的元素是不能重复的 从而能够进行比较 * */ data.clear() println(data) //Set() val map = mutable.Map.empty[String, String] map("java") = "Hadoop" map("scala") = "Spark" println(map) //Map(scala -> Spark, java -> Hadoop) println(map("java")) //Hadoop val treeSet = TreeSet(2, 3, 4, 1, 6, 8, 7) println(treeSet) //TreeSet(1, 2, 3, 4, 6, 7, 8) val treeMap = TreeMap("scala" -> "Spark", "java" -> "Hadoop") println(treeMap) //Map(java -> Hadoop, scala -> Spark) } }