These are shootings the hard ones again welcome to THE NEXT VIDEO OF THIS MORE deal of collections.
Now in this Mordieu We will check out the immutable collection and munity will collection.
So first of all in this video we will check out Voronezh list stands for it.
So in case of list we have the immutable list and also we have mutable list so we will check out when
Mavin borders the immutable and mutable list stands for and Vardar these functions such as list off
add a list aerialist off and mutate a list of Stine's for.
So let's check out when they went slowly inside the village.
The so in the previous video we checked out Vawter are at ease in case of Cartland.
Now they're demerit of at it is that it has a fixed size defined so we can change it later.
So here is what they will do is I will simply modify my code so here I will simply delete all these
scored from here in order to find a list.
We need to simply use the val or Val keyword and then simply use list equal to use the list of keyword.
Right and now here as a template.
Let us define string and now as a value you can simply define the content of the list such as Yugi move
in an enclosed space.
So here I have simply defined the immutable list by using the keyword off list of.
Now this is the type of list that we are having.
So this list variable will only contain the string values or you can say the Adye of string right.
So here as a value I have Yugi Manmohan and Viterbi we are having three string values right now.
As for this leg here this list of keyword only creates the immutable list.
Right.
So let me add a comment line here that is.
This list is actually immutable in nature and also it has fixed size and most importantly we can only
read from this list that is later on we can not modified the list or we can not write anything extra
to this list.
That is once the content of the list has been defined it cannot be changed.
What I'm trying to say is you cannot use such as list of legacy index to equal to.
Let's say something right.
ABC right.
You cannot do it because the Gorlin does not allow you to do it because the list is actually immutable
in nature.
You can not modify it later.
You can only perform the read operation.
Now what do you mean by the read operation is.
You can only print out the values present inside the list using the loops that we saw in the previous
video right.
And one more thing is common for this list compared to the areas that they list.
Also have the sequence index that is this UGI has the index of when this element has the index of.
Sorry this UGI has the index of 0.
Menuhin has the index of 1 and this Viterbi has the index of 2 and so on.
It will continue if we have for the elements right.
So as of now let us remove the elements of integer and in case you want to enter the in value so you
can simply define the type and simply replace all these value by integer values.
Now the same applies to the flawed order.
Let's say Boolean OR.
Let's see.
String.
Right.
And now let us print all these values such as.
I place my ADD A by list and then here.
Let us replace my addy by list.
Guard say is minus one right.
And here again.
Use list of the index.
Now apart from this list index of index you can simply use list Dorte get function and simply pass the
index.
So this loop is actually using the index of the element object to print out the values right and instead
of list of index you can simply use.
You can also use list don't get index so as of now let us read the code and see what happens.
So here we get Yugi and vice.
FE and again we get Yugi man who invites B.
Right so our courts are working perfectly fine.
Now suppose later on you want to add the fourth element that is here you want to add one more element.
So for Dagh this list off is actually immutable in nature.
So the solution for this is that you have to use the mutable list.
So here from the Slate You can check out the mutable list.
We have the added list option add a list of option table list of option so either of these three you
can use aspart of your choice.
So as of now let us replace this list off by let's see mutable list of.
Right.
So this makes our list mutable in nature.
So let me modify that comment line.
So this new stuff is actually mutable in nature and it has no fixed size.
You can add as many elements as you want to.
And also you can perform the add or remove operations such as read or write operations as discussed
because it is immutable in nature.
Right.
So inside the list what you can do is you can simply use.
You can simply add more elements such as list dord.
Let's see.
So here let me add UGI.
So if I add a Yugi here then you can remove Yugi from here.
Right.
Similarly you can add more elements after their declaration of the immutable list.
So since we have added the Menuhin and vice page here.
So let us remove these elements from here so it can be blank.
So this initialization of the list variable can be blank.
Right now after this.
Suppose if I run the call right now it is simply going to print out these three elements in the output
console as expected do you human way in rugby.
Now later on suppose you want to perform more operation on this new table list so far that you've already
really do is you can simply use as many metrics as you want to and these metrics are actually predefined
such as augmented replace all Metford remove the element at a specific index so the element at a specific
index get the size of the list and get a specific element at a particular index and so on.
Right.
So as of now what I would do I would simply remove the element of let's see Manmohan.
Right.
And instead of Manmohan and present are the index of let's say 1.
So here I've simply defined the index of the element.
This man movement is present at the index of when.
So instead of man move on I want to add more the so far that they really do list dord and Blue-Eyed
the index of let's see when are the index over and simply add more D instead of and more and let us
know than that or LHC if it happens or not.
So here in the outboard console we have a Yugi moody and vice.
So the Menuhin has been replaced by moody right now instead of this using the remove and add method
that is predefined.
We can also use list at the index of one equal to let's see with the light.
So this list are the index of one simply replace Vontae where it is present are the index of one by
more B.
So let us note in the chord.
So here we get you more the envoy's again.
So instead of using these two lines of code we have only one line of code that performs the same operation
as done by these two lines of code all together.
And now at the end instead of medievalist we can also have let's see add a list of strings and also
sort of this you can also use a list.
Now to be specific in all the cases we are actually using the table at least such as here we have to
add a list or string.
Here we have at a list of Metford that simply returns the ADD list.
Right.
And here again a list of actually returns the added list object.
So if you find that type Let's see or enter specify type explicitly you will find a mutable list which
is the mood Gendry form.
And here again for this or so you will find add a list of string.
And here again specify type explicitly you will find add a list of string.
Now this new table list is actually implemented by the add IList or a string.
So all these methods such as they will list off at a list off an add a list of all the same.
So you can use either of these three just for the sake of add more information.
I just showed you the explicit declaration so it has reverted back and here let me command these two
lines of code and here add a list or a string is again going to work perfectly fine.
Let us run the code and see if we're getting the same output or not.
Yes.
You gave me the advice again in the output console.
So remember at the end we have list of Metford that simply returns the immutable list.
And here we have the list such as add a list add it list off and list off.
You can use either of these three in your record.
So in the next two videos we will check our map and sex in Cartland.
So these things are signing off.
Thanks for watching and have a good day.
Thank you.