ArrayBuffers

In the following lesson, you will learn about ArrayBuffers and how they differ from ordinary arrays.

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.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy