1 00:00:00,590 --> 00:00:04,670 High this is getting at the heart once again welcome to the next video of this collection. 2 00:00:04,690 --> 00:00:05,740 More to now. 3 00:00:05,760 --> 00:00:10,400 In the previous two videos we talked about the Adye and list in girdling. 4 00:00:10,500 --> 00:00:13,930 So in this video we will discuss about the maps in Garling. 5 00:00:14,100 --> 00:00:19,250 So inside the map the Village Code Vawter immutable map and murid table map. 6 00:00:19,500 --> 00:00:25,190 So first of all let's take the immutable map that supports only read only operation using that method 7 00:00:25,200 --> 00:00:26,790 of map of. 8 00:00:26,790 --> 00:00:30,570 So here inside the intelligent Id let me clean up my code. 9 00:00:30,660 --> 00:00:35,250 So what is actually a map now the map is actually their data structure. 10 00:00:35,250 --> 00:00:40,250 So this data structure contains the elements in the form of key value pair. 11 00:00:40,470 --> 00:00:46,780 So each value is specified is connected to a specific key that you will check out shortly. 12 00:00:46,920 --> 00:00:49,770 So what do we mean by this is to define a map. 13 00:00:49,770 --> 00:00:52,620 We need to use the VAT or value keyword. 14 00:00:52,770 --> 00:00:56,730 Let's see my map equals to map of. 15 00:00:56,760 --> 00:01:00,620 Now this map of the regions the immutable map. 16 00:01:00,630 --> 00:01:08,070 Now this map of keyword actually returns the immutable map that is it cannot be mortified later once 17 00:01:08,090 --> 00:01:15,120 defined and it has also the fixed size and it can support the read only operation that is you can only 18 00:01:15,120 --> 00:01:20,340 read the content of the map but cannot modify in future aspart your requirement. 19 00:01:20,340 --> 00:01:24,760 So to define a map you can simply use map of followed by their template. 20 00:01:24,900 --> 00:01:30,210 Now their template contains the key value before the key can be laid. 21 00:01:30,260 --> 00:01:31,420 And in either case. 22 00:01:31,590 --> 00:01:33,680 And the value can be a string. 23 00:01:33,750 --> 00:01:39,380 Right now this key can also be a good order. 24 00:01:39,390 --> 00:01:41,650 This can also be flawed. 25 00:01:41,840 --> 00:01:44,090 But anarchies I'm keeping it in. 26 00:01:44,190 --> 00:01:44,820 Right. 27 00:01:44,910 --> 00:01:50,730 And this value can also be and and any combination can be applicable here. 28 00:01:50,760 --> 00:01:55,300 As you would wish and flowed into string into God and Boullion and so on. 29 00:01:55,500 --> 00:02:01,800 But right now just use string right now since we have defined the end and string as a key value period. 30 00:02:01,830 --> 00:02:03,360 That is the key will be in. 31 00:02:03,620 --> 00:02:05,100 And the value will be string. 32 00:02:05,100 --> 00:02:07,440 So inside the constructor. 33 00:02:07,770 --> 00:02:13,500 So while initializing all the values we have to define the key value pair in a similar fashion that 34 00:02:13,500 --> 00:02:16,980 is let us define the key as to who going to. 35 00:02:17,040 --> 00:02:24,720 Let's see Yugi separated by a comma second element Nerk see 43 going to alert them and move on. 36 00:02:24,780 --> 00:02:32,460 And then the third element does define the key value appeared as let's say seven going to be. 37 00:02:32,490 --> 00:02:35,030 So here I have simply defined the key value. 38 00:02:35,110 --> 00:02:42,030 Here is the key as a first element and as a first element I have the value of Yugi and here the key 39 00:02:42,030 --> 00:02:50,430 is 2:56 value as Menuhin keys 7 and value as fee now make a note here that inside the map since they 40 00:02:50,430 --> 00:02:51,850 are present in a sequence. 41 00:02:51,870 --> 00:02:55,690 But the key need not to be in sequence that is. 42 00:02:55,740 --> 00:02:57,770 This too can be fought as well. 43 00:02:57,780 --> 00:02:58,350 Right. 44 00:02:58,620 --> 00:03:02,400 And therefore it is not necessary that it has to be a greater number. 45 00:03:02,400 --> 00:03:05,140 It can be any number it can be one as well. 46 00:03:05,500 --> 00:03:07,220 So there is no sequence of the key. 47 00:03:07,230 --> 00:03:09,490 You're going to define any interior value. 48 00:03:09,630 --> 00:03:14,930 So the form will only map to Yugi and 43 will only map to 1. 49 00:03:15,090 --> 00:03:18,560 And now since this my map is actually immutable in nature. 50 00:03:18,570 --> 00:03:26,760 So you cannot say put any other elements inside this that is once defined you can not mortify in future 51 00:03:26,850 --> 00:03:31,800 you can only print or the values using the print and in the statement or the for loop. 52 00:03:31,830 --> 00:03:32,410 Right. 53 00:03:32,460 --> 00:03:38,820 So it's for this let's just print out the elements inside the immutable map by using the key. 54 00:03:38,820 --> 00:03:43,690 So here I would simply define the key and then my map door keys. 55 00:03:43,800 --> 00:03:47,510 So my map darkeys will simply return all the keys. 56 00:03:47,580 --> 00:03:51,830 Is fluid 43 and 7 and stewarded inside the key variable. 57 00:03:51,840 --> 00:03:52,720 One by one. 58 00:03:52,770 --> 00:04:00,230 So here I will simply use large see my map of key. 59 00:04:00,620 --> 00:04:07,060 So my map of Kiev is simply the return the value associated with that key that is your game and Mohon 60 00:04:07,100 --> 00:04:08,360 and speed. 61 00:04:08,870 --> 00:04:14,940 And in the output console you will get all the outputs the output. 62 00:04:14,950 --> 00:04:20,870 So here we go to Yugi maneuver and Vajpeyi And now instead of my map of the key. 63 00:04:20,890 --> 00:04:28,470 You can also right let's see my map Dorte get the value are this key. 64 00:04:28,610 --> 00:04:34,100 So instead of my map key you can also use my map dord get the value Akki right. 65 00:04:34,130 --> 00:04:35,560 So both ways it will work. 66 00:04:35,630 --> 00:04:37,480 So here let me mortify my brain. 67 00:04:37,500 --> 00:04:38,740 And in the statement. 68 00:04:39,170 --> 00:04:46,720 So here element present at this key and here I am simply appending are the key and also the map dot 69 00:04:46,740 --> 00:04:47,560 gate key. 70 00:04:47,570 --> 00:04:51,190 So here I will use my map and are get are in sort of this. 71 00:04:51,200 --> 00:04:54,530 You can also use my map are the index of key. 72 00:04:54,590 --> 00:04:55,130 Right. 73 00:04:55,160 --> 00:04:57,240 So let us note in the chord. 74 00:04:57,350 --> 00:05:04,200 So here we get element agcy that is Axford we have Yugi at 43 I have Manoharan at 7. 75 00:05:04,220 --> 00:05:05,720 I have Vice B. 76 00:05:05,810 --> 00:05:12,590 Now in future suppose you want to mortify large c I am going to modify my map so far that you can do 77 00:05:12,590 --> 00:05:15,080 it because it is immutable in nature. 78 00:05:15,080 --> 00:05:19,710 So the Cartland provides the mutable map that is immutable collections. 79 00:05:19,880 --> 00:05:21,170 So inside of them you will map. 80 00:05:21,170 --> 00:05:26,080 You can simply use hash map hash map of mewled table map of. 81 00:05:26,080 --> 00:05:29,760 So let us try these things inserted there in Delage ID. 82 00:05:29,780 --> 00:05:34,640 So any sort of map or if you can simply use the hash map. 83 00:05:34,640 --> 00:05:39,960 So this hash map again if you are from Java background then you must be familiar with this hash map. 84 00:05:40,040 --> 00:05:42,820 It contains a value as a key value pair. 85 00:05:42,830 --> 00:05:47,060 Now redefine a hash map there just remove all these called from here. 86 00:05:48,560 --> 00:05:56,760 And on that site I would simply use my map Dorte and then simply pass the first pyramided aski. 87 00:05:56,780 --> 00:05:57,220 Let's see. 88 00:05:57,220 --> 00:06:02,980 Food coma UGI and similarly I will add my movement and watch be. 89 00:06:03,050 --> 00:06:09,140 So here I have simply added two more elements and here this hash map is actually mutable in nature. 90 00:06:09,270 --> 00:06:14,080 There it is we can perform the read and write operation Buddh and it has no fixed size. 91 00:06:14,100 --> 00:06:14,560 There it is. 92 00:06:14,570 --> 00:06:17,000 In future we can add more and more elements. 93 00:06:17,030 --> 00:06:18,860 As for our vish. 94 00:06:19,060 --> 00:06:23,830 And now to print out all the elements the code will be same as we have defined here. 95 00:06:23,830 --> 00:06:28,960 So as of now let us run the call and we get the same output in the output console. 96 00:06:28,990 --> 00:06:29,640 Right. 97 00:06:29,740 --> 00:06:35,270 Now suppose in future you want to replace this man than by let's see Moody. 98 00:06:35,440 --> 00:06:41,220 So later on what we'll do inside your code you will simply use my map dord. 99 00:06:41,320 --> 00:06:44,550 Let's see say replace method. 100 00:06:44,590 --> 00:06:50,810 Now simply define the key as 43 and then the new value to be inserted. 101 00:06:51,000 --> 00:06:52,470 Legacy Mordy. 102 00:06:52,540 --> 00:06:53,990 So whatever is present. 103 00:06:54,010 --> 00:06:59,760 So whatever value is associated with 43 key will be replaced by Moody. 104 00:06:59,770 --> 00:07:03,760 So this movement will be removed and it will be replaced by Moody. 105 00:07:03,760 --> 00:07:06,260 So let us note in the chord. 106 00:07:06,450 --> 00:07:13,920 So here we get Axford we have Yugi seven vice B and at 43 instead of Menuhin I have more D. 107 00:07:14,190 --> 00:07:18,170 And now instead of using the replace you can also use the method. 108 00:07:18,230 --> 00:07:19,660 Now insert the apartment. 109 00:07:19,680 --> 00:07:22,660 If you pass 43 and then the new value. 110 00:07:22,830 --> 00:07:25,080 Then again it will work like replacement. 111 00:07:25,230 --> 00:07:30,330 So at 43 it will simply insert moody and maneuver and will be forgotten. 112 00:07:30,330 --> 00:07:31,780 So let's see what happens. 113 00:07:37,320 --> 00:07:41,910 So in the output again we have an index of agcy of 43. 114 00:07:41,910 --> 00:07:47,560 We have the someone movement is on now at the end of this video. 115 00:07:48,390 --> 00:07:54,960 I would like to show you a few more things now instead of hash mathy You can also use a few more keywords 116 00:07:55,020 --> 00:07:58,820 such as table map of. 117 00:07:58,950 --> 00:08:03,160 And also you can use hash map off. 118 00:08:03,830 --> 00:08:08,360 Now all these three are actually representing a hash map. 119 00:08:08,390 --> 00:08:18,320 The only difference is that this new table map of actually returns of the hash map. 120 00:08:18,340 --> 00:08:20,070 Now since this is a big net of course. 121 00:08:20,080 --> 00:08:22,930 So as of now I do not want to talk more about this link. 122 00:08:22,960 --> 00:08:29,410 Hash map but just remember more or less all these three are seeing all these three are actually returning 123 00:08:29,410 --> 00:08:30,340 a hash map. 124 00:08:30,550 --> 00:08:37,540 So in this video we talked about the map off and also hash map hash map off and mutable map of. 125 00:08:37,870 --> 00:08:42,540 And also we learned the difference between the mutable map and immutable map. 126 00:08:42,550 --> 00:08:48,640 So in the next video we will check out Vawter immutable set and they will have said that has their own 127 00:08:48,640 --> 00:08:52,600 functions such as say golf and your table is set off and so on. 128 00:08:52,600 --> 00:08:54,150 Let's take out in the next video. 129 00:08:54,190 --> 00:08:54,990 Thank you.