1
00:00:00,740 --> 00:00:01,380
Welcome back.

2
00:00:01,620 --> 00:00:05,790
So let's look at one more collection that is going to be the set.

3
00:00:06,180 --> 00:00:09,960
So that is a type of collection that eliminates duplicate data.

4
00:00:10,320 --> 00:00:13,860
This collection is unordered, which means the elements are not sorted.

5
00:00:14,250 --> 00:00:19,500
The midtable class is set off while the mutable types are mutable set off.

6
00:00:19,800 --> 00:00:21,570
And then there's also a hash set off.

7
00:00:21,960 --> 00:00:23,440
So let's look at an example here.

8
00:00:23,880 --> 00:00:30,840
So first, I'm going to create this fruit's example, which will be a set of, for example, orange.

9
00:00:31,170 --> 00:00:34,230
Then you have Apple Grape.

10
00:00:35,840 --> 00:00:39,860
And finally, another Apple while we're at it.

11
00:00:40,520 --> 00:00:46,880
So now let's go ahead and print the size of the fruits set.

12
00:00:47,300 --> 00:00:47,810
So here?

13
00:00:47,840 --> 00:00:51,290
Print size, like so let's run it.

14
00:00:52,760 --> 00:00:54,890
And you will see that at this press three.

15
00:00:55,610 --> 00:00:56,630
So what's up here?

16
00:00:57,170 --> 00:01:04,700
Well, that is because our orange or apple and our grape are the only unique items inside of the set.

17
00:01:05,030 --> 00:01:06,230
It ignores this apple.

18
00:01:06,440 --> 00:01:09,200
Now let's add mango in here, for example, as well.

19
00:01:09,500 --> 00:01:12,320
And I'm going to put that right there.

20
00:01:12,890 --> 00:01:13,910
Mango.

21
00:01:15,080 --> 00:01:15,980
Very tasty.

22
00:01:16,460 --> 00:01:20,000
So we have orange, apple, mango grape and another apple.

23
00:01:20,300 --> 00:01:23,690
Now you could go as far as to add another orange.

24
00:01:24,230 --> 00:01:28,280
And what you will see is that you still get an while.

25
00:01:28,280 --> 00:01:33,560
This time you get four because we had the mango, but the apple and orange, the duplicates, so to

26
00:01:33,560 --> 00:01:35,060
speak, they are ignored.

27
00:01:35,600 --> 00:01:38,270
They are not taken into consideration.

28
00:01:38,630 --> 00:01:43,460
Now the cool thing is we can sort this list so we can, of course, also display fruits.

29
00:01:43,610 --> 00:01:44,990
So let's run this real quick.

30
00:01:45,590 --> 00:01:47,360
We'll see orange apple mango grape.

31
00:01:47,360 --> 00:01:55,000
So it ignored all of the additional details, and now we can also sort it by using two sorted set.

32
00:01:55,640 --> 00:01:57,080
So that's a very cool feature.

33
00:01:57,470 --> 00:02:02,390
So let's do that and you see Apple Grape, Mango Orange, so it's sorted it alphabetically.

34
00:02:04,700 --> 00:02:08,120
Now, the problem with this set is that it's not mutable.

35
00:02:08,270 --> 00:02:11,360
So let's go ahead and create a mutable list.

36
00:02:11,510 --> 00:02:17,240
So I'm going to call this one new fruits, and it will be a fruits to mutable list.

37
00:02:17,250 --> 00:02:22,190
So now this time we are converting our fruits into a mutable list of fruits.

38
00:02:22,880 --> 00:02:26,990
And now we can go ahead and use new fruits in order to add items to it.

39
00:02:27,080 --> 00:02:31,730
So, for example, a watermelon would be a very good addition to this.

40
00:02:32,030 --> 00:02:37,180
And then let's add another beautiful fruit that would be a pear.

41
00:02:38,990 --> 00:02:40,300
Like, so OK.

42
00:02:40,320 --> 00:02:41,900
And then let's print those.

43
00:02:42,110 --> 00:02:45,920
So print new fruits and let's see what we're going to get.

44
00:02:47,840 --> 00:02:50,280
And we see we have Apple Grape, Mango Orange.

45
00:02:50,300 --> 00:02:55,220
This is the first entry, this is this print statement on let me get rid of it in order to make this

46
00:02:55,220 --> 00:02:56,370
look a little smoother.

47
00:02:56,390 --> 00:02:58,970
We see orange, apple, mango, grape, watermelon, pear.

48
00:02:59,750 --> 00:03:02,660
OK, so it added those entries for us.

49
00:03:05,100 --> 00:03:08,250
We want to access a particular fruit in your list.

50
00:03:08,580 --> 00:03:13,920
You can go ahead and just use the element pat.

51
00:03:14,700 --> 00:03:17,490
And then the number that you want to have.

52
00:03:17,820 --> 00:03:19,870
So new fruits element at four.

53
00:03:19,890 --> 00:03:25,470
Let's see what's going to happen there and we see we get the watermelon because the watermelon at this

54
00:03:25,470 --> 00:03:31,710
point is at the index four, which means it's the fifth fruit because we have orange, apple, mango

55
00:03:31,710 --> 00:03:32,250
and grape.

56
00:03:32,250 --> 00:03:33,510
And then we have the watermelon.

57
00:03:33,510 --> 00:03:40,530
And that's index four because oranges at zero, apple at one mango, two grape at three watermelon four

58
00:03:40,530 --> 00:03:41,460
and pear at five.

59
00:03:43,660 --> 00:03:48,820
OK, now let's look at maps, OK, and we're not going to look at Google Maps or so, but we're going

60
00:03:48,820 --> 00:03:53,290
to create a map of where a map list of kind of collection.

61
00:03:53,710 --> 00:03:59,800
So Map is a type of collection that holds data in the form of a key value pair, and the map keys are

62
00:03:59,800 --> 00:04:03,280
unique and hold only one value for each key.

63
00:04:03,700 --> 00:04:04,570
So let's look at that.

64
00:04:04,840 --> 00:04:11,080
So we have days of the week, for example, and this time we're going to use a map of here.

65
00:04:11,650 --> 00:04:16,000
So this will be a map of one to Monday, for example.

66
00:04:16,089 --> 00:04:17,019
That's how you can map.

67
00:04:17,260 --> 00:04:18,209
Very easy way.

68
00:04:18,220 --> 00:04:18,760
Pretty cool.

69
00:04:18,910 --> 00:04:21,230
And here you need to have the empty spaces.

70
00:04:21,250 --> 00:04:31,060
So one to Monday, then two to four example Tuesday at three to Wednesday.

71
00:04:31,870 --> 00:04:32,230
So.

72
00:04:33,270 --> 00:04:42,720
I have now connected the numbers to the dates, and that means that this key, this is the key is connected

73
00:04:42,720 --> 00:04:44,160
to the value of Wednesday.

74
00:04:44,550 --> 00:04:48,060
The key one is connected to the value of Monday.

75
00:04:48,120 --> 00:04:52,170
So this key can only be existing once each key only exists once.

76
00:04:52,500 --> 00:04:53,670
So this is a map.

77
00:04:53,910 --> 00:04:59,190
But in other languages, this is also called a hash map or a dictionary.

78
00:04:59,200 --> 00:05:03,720
So depending on which programming language you're looking at, it just has different names.

79
00:05:05,070 --> 00:05:12,660
And then we can now go ahead and, for example, access a particular item or print days of week at position

80
00:05:12,660 --> 00:05:15,570
two, for example, would give us Tuesday.

81
00:05:16,020 --> 00:05:19,200
OK, so here we're not talking about the index, but the actual key.

82
00:05:19,620 --> 00:05:22,590
OK gets the key value and not the index.

83
00:05:23,370 --> 00:05:31,650
So let's run this and we will get the Tuesday entry because it is connected to the key of two if you

84
00:05:31,650 --> 00:05:35,700
want to loop through your items inside of a map.

85
00:05:35,880 --> 00:05:43,860
You can just go ahead and use for loop again, saying key in days of week dot keys.

86
00:05:44,340 --> 00:05:49,470
So now we're going through the individual keys and let's print.

87
00:05:50,790 --> 00:05:54,540
The key is to and then.

88
00:05:55,790 --> 00:05:57,830
The days of week dot.

89
00:05:58,640 --> 00:06:00,110
Well, in this case.

90
00:06:01,460 --> 00:06:09,890
The square brackets key and what this will give us, it will tell us what the key is and it will tell

91
00:06:09,890 --> 00:06:12,140
us the item that it is connected to.

92
00:06:12,170 --> 00:06:14,840
So this is the value that it's connected to.

93
00:06:15,110 --> 00:06:21,080
And here I'm using numbers to strings, but this could also be strings to, for example, objects.

94
00:06:21,230 --> 00:06:22,850
So you're not limited here.

95
00:06:23,360 --> 00:06:25,490
It's what gives you a lot of freedom here.

96
00:06:25,910 --> 00:06:27,240
So let's run this and see.

97
00:06:27,260 --> 00:06:30,170
One is to Monday to is to choose two entries to wed.

98
00:06:30,740 --> 00:06:36,530
So just a quick example of using our fruit data again.

99
00:06:36,590 --> 00:06:48,770
So here, data class fruit, which contains the value of name, which will be a string and then price,

100
00:06:49,520 --> 00:06:52,760
which will be a double.

101
00:06:55,040 --> 00:07:05,840
OK, so we have this beautiful fruit now, this fruit class, and now we could go ahead and say fruits.

102
00:07:06,590 --> 00:07:11,120
It's going to be a map of this will be fruits map.

103
00:07:11,720 --> 00:07:12,680
Let's call it like this.

104
00:07:12,950 --> 00:07:14,960
So that is unique map of.

105
00:07:15,530 --> 00:07:26,120
And then I connect, for example, one to my fruit, which is going to be grape and has the price of

106
00:07:26,120 --> 00:07:26,960
two point five.

107
00:07:27,440 --> 00:07:33,320
And then we have to assigned to fruit that will be mine actually here.

108
00:07:33,320 --> 00:07:39,020
You could even go ahead and use not grape, but favorite fruit, something like this favorite.

109
00:07:40,010 --> 00:07:43,100
And this would be OK.

110
00:07:44,120 --> 00:07:46,100
And here the fruit would be.

111
00:07:47,250 --> 00:07:51,990
Apple, even though I love apples and it has the price of.

112
00:07:53,690 --> 00:07:58,430
One Euro 1.0 euro in order to press to be precise.

113
00:07:59,090 --> 00:08:01,820
OK, so that will be our map of.

114
00:08:02,330 --> 00:08:07,060
And me find a good point to set the brake.

115
00:08:07,190 --> 00:08:15,680
So you see, we have this fruits map of where our key this time is a string and the value is an object.

116
00:08:16,010 --> 00:08:21,620
In our simple example here, our key was a number and the value was a string.

117
00:08:21,950 --> 00:08:28,340
So you can make whatever connections you want to have here, which is why maps are so powerful.

118
00:08:33,820 --> 00:08:40,090
Now, if you want to make changes, you need to make it a mutable list.

119
00:08:40,690 --> 00:08:50,530
So here I can just go ahead and change that to all new days of week or new day of week.

120
00:08:51,010 --> 00:08:53,560
And that will be days of the week.

121
00:08:55,700 --> 00:08:56,240
OK.

122
00:08:56,990 --> 00:09:04,460
And I'm going to make it the mutable map, so to mute a mob and now I can use the new days of the week

123
00:09:04,700 --> 00:09:10,490
to assign, for example, at the position four I can add.

124
00:09:11,840 --> 00:09:12,680
First day.

125
00:09:14,180 --> 00:09:18,170
And then at position five, I could add.

126
00:09:19,160 --> 00:09:19,880
Friday.

127
00:09:21,470 --> 00:09:22,130
And so forth.

128
00:09:22,580 --> 00:09:22,920
OK.

129
00:09:23,330 --> 00:09:28,250
And you can now sort her map by using the two sorted map method.

130
00:09:28,460 --> 00:09:38,570
So here, Brent new days of week dot to sorted map out this well sort of map for us.

131
00:09:38,660 --> 00:09:45,350
Let's run this real quick and we can see we have the sorted map and actually we have another print statements

132
00:09:45,350 --> 00:09:48,830
somewhere, which makes this a little more difficult to read.

133
00:09:48,830 --> 00:09:51,110
I believe this one.

134
00:09:51,440 --> 00:09:56,600
So let's get rid of this and run it again, and we can see now it's sorted.

135
00:09:57,290 --> 00:10:01,400
It's Monday, Tuesday, Wednesday, Thursday, Friday, and it's sorted by its key.

136
00:10:03,640 --> 00:10:08,770
So just like other collections, MEPs also have a bunch of different methods that you can play around

137
00:10:08,770 --> 00:10:09,020
with.

138
00:10:09,040 --> 00:10:15,040
So I would really recommend that you just go ahead and use to dot operator and just give yourself some

139
00:10:15,040 --> 00:10:15,460
hints.

140
00:10:15,790 --> 00:10:21,370
OK, so what you can do here, for example, it doesn't have an ad method, but it has other methods.

141
00:10:21,520 --> 00:10:25,350
So here, if you press the dot key, you can see there are a bunch of methods.

142
00:10:25,360 --> 00:10:29,110
In my case, the idea seems to be broken, so I'm going to fix that.

143
00:10:29,920 --> 00:10:31,660
OK, so that's it for this video.

144
00:10:31,750 --> 00:10:32,740
See you in the next one.

