Inside a function of mine I construct a result set by filling a new mutable HashMap with data (if there is a better way – I'd appreciate comments). Then I'd like to return the result set as an immutable HashMap. How to derive an immutable from a mutable?
Scala – How to convert a mutable HashMap into an immutable equivalent in Scala
immutabilitymutablescalascala-collections
Best Answer
Discussion about returning
immutable.Map
vs.immutable.HashMap
notwithstanding, what about simply using thetoMap
method:As of 2.9, this uses the method
toMap
inTraversableOnce
, which is implemented as follows: