Change default capacity/load factor of scala mutable.HashMap

collections, scala

Solution

According to the API, this does not seem to be possible. One explanation is that mutable collections are strongly discouraged, and immutable collections don't need the default capacity information since the number of items must be known at the time of construction.

However, note that Scala will implicitly use default capacity information if you construct a collection (including mutable and immutable `HashMap`) via the many available collection methods. For example, if you call `map` on a `HashMap`, it will use `map` defined on `TraversableLike` (reproduced below), and you can see that it provides a "size hint" to the builder that provides that capacity information.

def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
  val b = bf(repr)
  b.sizeHint(this)
  for (x <- this) b += f(x)
  b.result
}

Problem

I am currently using scala 2.9.1. I create a mutable.HashMap using : ``` > val m = mutable.HashMap.empty[Int, Int] ``` I am kind of new to scala. In java, I was able to specify the capacity and load factor in the constructor of a HashMap. I am not able to find any way to do the same in scala. Thanks in Advance

Original source