#odersky-programming-in-scala-1ed #scala
Both mutable and immutable sets offer a + method, but their behavior differs.
Whereas a mutable set will add the element to itself, an immutable set will create
and return a new set with the element added.
If you want to change selection, open document below and click on "Move attachment"
Next Steps in Scalaala.collection.immutable.Set,
which returns an instance of a default, immutable Set. The Scala compiler
infers jetSet's type to be the immutable Set[String].
To add a new element to a set, you call + on the set, passing in the new element.
<span>Both mutable and immutable sets offer a + method, but their behavior differs.
Whereas a mutable set will add the element to itself, an immutable set will create
and return a new set with the element added. In Listing 3.5,
you're working with an immutable set, thus the + invocation will yield a brand
new set. Although mutable sets offer an actual += method, immutable sets do
not. In this ca Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details