1 00:00:05,500 --> 00:00:10,520 These are shootings the hard ones again welcome to THE NEXT VIDEO OF THIS MORE deal of collections. 2 00:00:10,580 --> 00:00:16,340 Now in this Mordieu We will check out the immutable collection and munity will collection. 3 00:00:16,340 --> 00:00:20,780 So first of all in this video we will check out Voronezh list stands for it. 4 00:00:20,930 --> 00:00:27,470 So in case of list we have the immutable list and also we have mutable list so we will check out when 5 00:00:27,530 --> 00:00:34,230 Mavin borders the immutable and mutable list stands for and Vardar these functions such as list off 6 00:00:34,350 --> 00:00:38,060 add a list aerialist off and mutate a list of Stine's for. 7 00:00:38,330 --> 00:00:42,130 So let's check out when they went slowly inside the village. 8 00:00:42,220 --> 00:00:48,170 The so in the previous video we checked out Vawter are at ease in case of Cartland. 9 00:00:48,290 --> 00:00:54,700 Now they're demerit of at it is that it has a fixed size defined so we can change it later. 10 00:00:54,710 --> 00:01:00,240 So here is what they will do is I will simply modify my code so here I will simply delete all these 11 00:01:00,250 --> 00:01:02,810 scored from here in order to find a list. 12 00:01:02,810 --> 00:01:12,310 We need to simply use the val or Val keyword and then simply use list equal to use the list of keyword. 13 00:01:12,620 --> 00:01:15,160 Right and now here as a template. 14 00:01:15,200 --> 00:01:23,500 Let us define string and now as a value you can simply define the content of the list such as Yugi move 15 00:01:23,510 --> 00:01:25,800 in an enclosed space. 16 00:01:26,090 --> 00:01:31,140 So here I have simply defined the immutable list by using the keyword off list of. 17 00:01:31,140 --> 00:01:34,210 Now this is the type of list that we are having. 18 00:01:34,310 --> 00:01:41,260 So this list variable will only contain the string values or you can say the Adye of string right. 19 00:01:41,360 --> 00:01:49,280 So here as a value I have Yugi Manmohan and Viterbi we are having three string values right now. 20 00:01:49,400 --> 00:01:54,600 As for this leg here this list of keyword only creates the immutable list. 21 00:01:54,630 --> 00:01:55,340 Right. 22 00:01:55,610 --> 00:01:58,930 So let me add a comment line here that is. 23 00:01:58,940 --> 00:02:06,080 This list is actually immutable in nature and also it has fixed size and most importantly we can only 24 00:02:06,080 --> 00:02:12,790 read from this list that is later on we can not modified the list or we can not write anything extra 25 00:02:12,830 --> 00:02:13,880 to this list. 26 00:02:14,000 --> 00:02:18,580 That is once the content of the list has been defined it cannot be changed. 27 00:02:18,590 --> 00:02:26,240 What I'm trying to say is you cannot use such as list of legacy index to equal to. 28 00:02:26,260 --> 00:02:28,220 Let's say something right. 29 00:02:28,370 --> 00:02:29,550 ABC right. 30 00:02:29,630 --> 00:02:35,720 You cannot do it because the Gorlin does not allow you to do it because the list is actually immutable 31 00:02:35,720 --> 00:02:36,410 in nature. 32 00:02:36,440 --> 00:02:38,300 You can not modify it later. 33 00:02:38,330 --> 00:02:41,180 You can only perform the read operation. 34 00:02:41,240 --> 00:02:43,710 Now what do you mean by the read operation is. 35 00:02:43,730 --> 00:02:49,820 You can only print out the values present inside the list using the loops that we saw in the previous 36 00:02:49,880 --> 00:02:50,840 video right. 37 00:02:51,110 --> 00:02:57,750 And one more thing is common for this list compared to the areas that they list. 38 00:02:57,750 --> 00:03:04,990 Also have the sequence index that is this UGI has the index of when this element has the index of. 39 00:03:05,030 --> 00:03:08,360 Sorry this UGI has the index of 0. 40 00:03:08,370 --> 00:03:13,420 Menuhin has the index of 1 and this Viterbi has the index of 2 and so on. 41 00:03:13,440 --> 00:03:16,940 It will continue if we have for the elements right. 42 00:03:17,070 --> 00:03:23,580 So as of now let us remove the elements of integer and in case you want to enter the in value so you 43 00:03:23,580 --> 00:03:29,160 can simply define the type and simply replace all these value by integer values. 44 00:03:29,160 --> 00:03:31,920 Now the same applies to the flawed order. 45 00:03:32,070 --> 00:03:33,860 Let's say Boolean OR. 46 00:03:33,930 --> 00:03:34,690 Let's see. 47 00:03:34,710 --> 00:03:35,720 String. 48 00:03:36,070 --> 00:03:36,590 Right. 49 00:03:37,010 --> 00:03:40,000 And now let us print all these values such as. 50 00:03:40,020 --> 00:03:44,090 I place my ADD A by list and then here. 51 00:03:44,130 --> 00:03:46,500 Let us replace my addy by list. 52 00:03:46,520 --> 00:03:48,480 Guard say is minus one right. 53 00:03:48,770 --> 00:03:49,540 And here again. 54 00:03:49,550 --> 00:03:51,740 Use list of the index. 55 00:03:51,770 --> 00:04:01,900 Now apart from this list index of index you can simply use list Dorte get function and simply pass the 56 00:04:01,900 --> 00:04:02,860 index. 57 00:04:03,250 --> 00:04:10,190 So this loop is actually using the index of the element object to print out the values right and instead 58 00:04:10,200 --> 00:04:12,190 of list of index you can simply use. 59 00:04:12,190 --> 00:04:18,900 You can also use list don't get index so as of now let us read the code and see what happens. 60 00:04:19,760 --> 00:04:22,310 So here we get Yugi and vice. 61 00:04:22,320 --> 00:04:25,420 FE and again we get Yugi man who invites B. 62 00:04:25,430 --> 00:04:29,060 Right so our courts are working perfectly fine. 63 00:04:29,470 --> 00:04:36,230 Now suppose later on you want to add the fourth element that is here you want to add one more element. 64 00:04:36,960 --> 00:04:41,300 So for Dagh this list off is actually immutable in nature. 65 00:04:41,490 --> 00:04:45,310 So the solution for this is that you have to use the mutable list. 66 00:04:45,390 --> 00:04:48,620 So here from the Slate You can check out the mutable list. 67 00:04:48,630 --> 00:04:55,650 We have the added list option add a list of option table list of option so either of these three you 68 00:04:55,650 --> 00:04:57,570 can use aspart of your choice. 69 00:04:57,570 --> 00:05:05,180 So as of now let us replace this list off by let's see mutable list of. 70 00:05:05,300 --> 00:05:06,140 Right. 71 00:05:06,290 --> 00:05:10,010 So this makes our list mutable in nature. 72 00:05:10,010 --> 00:05:12,350 So let me modify that comment line. 73 00:05:12,350 --> 00:05:18,070 So this new stuff is actually mutable in nature and it has no fixed size. 74 00:05:18,080 --> 00:05:20,830 You can add as many elements as you want to. 75 00:05:21,050 --> 00:05:27,380 And also you can perform the add or remove operations such as read or write operations as discussed 76 00:05:27,500 --> 00:05:29,380 because it is immutable in nature. 77 00:05:29,480 --> 00:05:30,000 Right. 78 00:05:30,980 --> 00:05:34,530 So inside the list what you can do is you can simply use. 79 00:05:34,610 --> 00:05:38,030 You can simply add more elements such as list dord. 80 00:05:38,050 --> 00:05:39,070 Let's see. 81 00:05:39,320 --> 00:05:42,570 So here let me add UGI. 82 00:05:42,710 --> 00:05:46,970 So if I add a Yugi here then you can remove Yugi from here. 83 00:05:47,090 --> 00:05:47,770 Right. 84 00:05:47,780 --> 00:05:54,100 Similarly you can add more elements after their declaration of the immutable list. 85 00:05:54,110 --> 00:05:57,110 So since we have added the Menuhin and vice page here. 86 00:05:57,200 --> 00:06:01,560 So let us remove these elements from here so it can be blank. 87 00:06:01,760 --> 00:06:06,430 So this initialization of the list variable can be blank. 88 00:06:06,980 --> 00:06:09,260 Right now after this. 89 00:06:09,440 --> 00:06:14,750 Suppose if I run the call right now it is simply going to print out these three elements in the output 90 00:06:14,750 --> 00:06:18,370 console as expected do you human way in rugby. 91 00:06:18,410 --> 00:06:24,470 Now later on suppose you want to perform more operation on this new table list so far that you've already 92 00:06:24,470 --> 00:06:30,230 really do is you can simply use as many metrics as you want to and these metrics are actually predefined 93 00:06:30,620 --> 00:06:38,600 such as augmented replace all Metford remove the element at a specific index so the element at a specific 94 00:06:38,660 --> 00:06:45,390 index get the size of the list and get a specific element at a particular index and so on. 95 00:06:45,390 --> 00:06:45,880 Right. 96 00:06:46,040 --> 00:06:54,650 So as of now what I would do I would simply remove the element of let's see Manmohan. 97 00:06:54,710 --> 00:06:55,310 Right. 98 00:06:55,500 --> 00:07:00,000 And instead of Manmohan and present are the index of let's say 1. 99 00:07:00,030 --> 00:07:02,580 So here I've simply defined the index of the element. 100 00:07:02,610 --> 00:07:05,280 This man movement is present at the index of when. 101 00:07:05,460 --> 00:07:13,660 So instead of man move on I want to add more the so far that they really do list dord and Blue-Eyed 102 00:07:13,660 --> 00:07:20,950 the index of let's see when are the index over and simply add more D instead of and more and let us 103 00:07:20,950 --> 00:07:24,520 know than that or LHC if it happens or not. 104 00:07:24,520 --> 00:07:28,070 So here in the outboard console we have a Yugi moody and vice. 105 00:07:28,120 --> 00:07:35,740 So the Menuhin has been replaced by moody right now instead of this using the remove and add method 106 00:07:35,850 --> 00:07:36,930 that is predefined. 107 00:07:36,940 --> 00:07:44,570 We can also use list at the index of one equal to let's see with the light. 108 00:07:44,620 --> 00:07:51,130 So this list are the index of one simply replace Vontae where it is present are the index of one by 109 00:07:51,220 --> 00:07:51,750 more B. 110 00:07:51,760 --> 00:07:54,900 So let us note in the chord. 111 00:07:55,060 --> 00:07:58,170 So here we get you more the envoy's again. 112 00:07:58,240 --> 00:08:04,450 So instead of using these two lines of code we have only one line of code that performs the same operation 113 00:08:04,480 --> 00:08:07,810 as done by these two lines of code all together. 114 00:08:07,960 --> 00:08:19,600 And now at the end instead of medievalist we can also have let's see add a list of strings and also 115 00:08:19,780 --> 00:08:23,630 sort of this you can also use a list. 116 00:08:23,910 --> 00:08:31,530 Now to be specific in all the cases we are actually using the table at least such as here we have to 117 00:08:31,530 --> 00:08:33,030 add a list or string. 118 00:08:33,150 --> 00:08:38,030 Here we have at a list of Metford that simply returns the ADD list. 119 00:08:38,040 --> 00:08:38,730 Right. 120 00:08:38,760 --> 00:08:43,770 And here again a list of actually returns the added list object. 121 00:08:43,770 --> 00:08:52,080 So if you find that type Let's see or enter specify type explicitly you will find a mutable list which 122 00:08:52,080 --> 00:08:53,820 is the mood Gendry form. 123 00:08:53,880 --> 00:08:59,690 And here again for this or so you will find add a list of string. 124 00:08:59,760 --> 00:09:05,720 And here again specify type explicitly you will find add a list of string. 125 00:09:05,720 --> 00:09:10,330 Now this new table list is actually implemented by the add IList or a string. 126 00:09:10,340 --> 00:09:16,230 So all these methods such as they will list off at a list off an add a list of all the same. 127 00:09:16,250 --> 00:09:20,390 So you can use either of these three just for the sake of add more information. 128 00:09:20,420 --> 00:09:28,710 I just showed you the explicit declaration so it has reverted back and here let me command these two 129 00:09:28,710 --> 00:09:33,570 lines of code and here add a list or a string is again going to work perfectly fine. 130 00:09:33,570 --> 00:09:38,220 Let us run the code and see if we're getting the same output or not. 131 00:09:38,820 --> 00:09:39,110 Yes. 132 00:09:39,150 --> 00:09:42,000 You gave me the advice again in the output console. 133 00:09:42,300 --> 00:09:48,860 So remember at the end we have list of Metford that simply returns the immutable list. 134 00:09:49,020 --> 00:09:55,460 And here we have the list such as add a list add it list off and list off. 135 00:09:55,470 --> 00:09:58,270 You can use either of these three in your record. 136 00:09:58,320 --> 00:10:02,390 So in the next two videos we will check our map and sex in Cartland. 137 00:10:02,490 --> 00:10:04,330 So these things are signing off. 138 00:10:04,380 --> 00:10:06,080 Thanks for watching and have a good day. 139 00:10:06,120 --> 00:10:06,820 Thank you.