Scala's mutable, immutable object

Apr232010

Screen shot 2010-04-24 at 12.59.32 PM.png
1.creating, initializing, and using an immutable set:
var jetSet = Set("Boeing", "Airbus")
jetSet += "Lear"
println(jetSet.contains("Cessna"))

2.creating, initializing, and using a mutable set:
import scala.collection.mutable.set
val movieSet = Set("Hitch", "Poltergeist")
movieSet += "Shrek"
println(movieSet)

Because the set in 2 is mutable, there is no need to reassign movieSet,
which is why it can be a val. By contrast, using += with the immutable set
in 1 required reassigning jetSet, which is why it must be a var.