Mutable vs. Immutable1:37 with andi mitre
In this video we’ll get a quick overview of the different data structures that Scala has to offer. We will take a look at the mutable and immutable collections and how to import each one.
Immutable collections -- A collection which cannot be updated or extended in place such as lists.
Mutable collections -- A collection which can be updated or extended in place instead of yielding a new collection such as arrays.
[MUSIC] 0:00 Hi, welcome to Scala Collections. 0:04 In the following videos we'll learn about collections in Scala. 0:07 Collections are a crucial part of any language and 0:11 they can range from immutable to mutable. 0:14 A mutable collection can be extended or it's contents can be updated in place. 0:17 Whereas immutable collection never changes. 0:22 Be aware that certain immutable collections may have methods to which can 0:26 update, add or remove elements but these operations will always yield 0:30 a new collection and leaves the existing collection intact. 0:35 Scala gives preference to immutable collections. 0:39 Scala collection classes can be found in scala.collection pagkage 0:42 which contains the sub packages scala.collection.immutable and 0:47 scala.collection.mutable. 0:51 The immutable package contains collections which guarantee that the elements 0:54 will not change. 0:58 Meanwhile scala.collection.mutable provides us with operations 0:59 to change the collections in place. 1:04 For instance a raise in scala are considered mutable 1:07 because we can update the values of the array. 1:10 While list are considered immutable because we're not able to update elements 1:13 within a list. 1:18 However you'll notice that we are able to append or prepend elements to our list. 1:19 Remember in that case a new collection will be created and 1:25 the original list will remain untouched. 1:28 In the following videos we'll dive deeper into scalar collections and 1:31 begin using them in our projects. 1:35
You need to sign up for Treehouse in order to download course files.Sign up