import scala.collection.mutable.Set //必需要導入這個包scala
val mylist = Array("a1","b2","c3")io
var myset:Set[String] = Set()
mylist.foreach(s=>{val as = s+"!"
myset += as //給set
println(as)
})
println("------------")
myset.foreach(s=>println(s))
println("------------")table
打印結果:import
a1!
b2!
c3!
------------
c3!
a1!
b2!
------------foreach