hollow7 hollow7 - 1 year ago 111
Scala Question

Scala's += method for mutable collections

What does the += method for scale's mutable collections gets translated to behind the scenes?

For example, if I do += on a mutable queue, is that equivalent to doing an enqueue? Ditto for -=?

Answer Source

According to the source code, enqueue is implemented as:

def enqueue(elems: A*): Unit = this ++= elems

The dequeue code is more complicated and not equivalent to -= as there is no -= method for a Queue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download