Introduction
Creating an ArrayBuffer
Adding Elements
Deleting Elements
-= Assignment Operator
remove method
clear method
Introduction
An ArrayBuffer in Scala is a collection that comes under the sequence class. Like Arrays, it is a mutable collection, hence, when elements in an ArrayBuffer are modified, the original ArrayBuffer is updated.
ArrayBuffers are very similar to arrays with the difference that you can add and remove elements from an ArrayBuffer while adding and removing elements is not possible in simple Arrays.
Array methods and operations are also available for ArrayBuffers.
Creating an ArrayBuffer#
To be able to use an ArrayBuffer, we first need to import it using the package scala.collection.mutable.ArrayBuffer. Afterward, you can create and populate an ArrayBuffer the same way you create an Array.