ListBufferには+=:で末尾に要素追加
+=:
で末尾に要素を追加できる。
scala> import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer scala> val buf = new ListBuffer[Int] buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer() scala> buf += 1 res37: buf.type = ListBuffer(1) scala> buf += 2 res38: buf.type = ListBuffer(1, 2) scala> buf res39: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2) scala> 3 +=: buf res40: buf.type = ListBuffer(3, 1, 2)
コップ本 p.320より。 http://www.amazon.co.jp/dp/4844330845/