1 00:00:00,690 --> 00:00:02,850 ‫-: Hi. Inside of this lecture, 2 00:00:02,850 --> 00:00:06,060 ‫we are going to see what is a set. 3 00:00:06,060 --> 00:00:08,580 ‫So there is a data structure called HashSet 4 00:00:08,580 --> 00:00:10,601 ‫and it's very similar to arrays 5 00:00:10,601 --> 00:00:14,100 ‫but with a big major difference. 6 00:00:14,100 --> 00:00:16,140 ‫So it's written like this: 7 00:00:16,140 --> 00:00:21,140 ‫set and you can call set with HashSet type. 8 00:00:21,150 --> 00:00:24,690 ‫Now the major difference between arrays and sets 9 00:00:24,690 --> 00:00:29,690 ‫that a number eight string or any type of value 10 00:00:30,030 --> 00:00:33,420 ‫can be present in a set only once. 11 00:00:33,420 --> 00:00:36,330 ‫So you cannot have the same value 12 00:00:36,330 --> 00:00:39,450 ‫more than once inside of a HashSet. 13 00:00:39,450 --> 00:00:41,850 ‫We're going to see what the HashMap is. 14 00:00:41,850 --> 00:00:44,760 ‫Now we are interested in HashSet. 15 00:00:44,760 --> 00:00:49,260 ‫Okay, so choose, choose HashSet from here 16 00:00:49,260 --> 00:00:52,440 ‫and open this angular braces and write String, 17 00:00:52,440 --> 00:00:56,790 ‫for example, you can store any type that you want over here 18 00:00:56,790 --> 00:00:59,280 ‫and I'm gonna call this mySet 19 00:00:59,280 --> 00:01:02,580 ‫and this will be initialized as we did 20 00:01:02,580 --> 00:01:05,010 ‫in the ArrayList as well. 21 00:01:05,010 --> 00:01:08,160 ‫After that, you can actually add any element 22 00:01:08,160 --> 00:01:11,730 ‫that you want like we did in the ArrayList as well. 23 00:01:11,730 --> 00:01:14,010 ‫So you can just say mySet dot add, 24 00:01:14,010 --> 00:01:15,990 ‫it will expect some string. 25 00:01:15,990 --> 00:01:19,590 ‫For example, give James, and over here, 26 00:01:19,590 --> 00:01:22,230 ‫add James one more time 27 00:01:22,230 --> 00:01:24,570 ‫and in an exact way that you have written. 28 00:01:24,570 --> 00:01:28,200 ‫For example, if you have written with an upper case J, 29 00:01:28,200 --> 00:01:31,170 ‫then you should write it with an upper case J 30 00:01:31,170 --> 00:01:34,020 ‫one more time because over here, 31 00:01:34,020 --> 00:01:38,633 ‫I'm going to see the size of mySet. 32 00:01:39,960 --> 00:01:44,430 ‫So if you do mySet dot size, it will print 33 00:01:44,430 --> 00:01:49,430 ‫out the current numbers of elements inside of your set. 34 00:01:50,190 --> 00:01:52,650 ‫You can use this in your ArrayList as well. 35 00:01:52,650 --> 00:01:54,690 ‫For example, you can do something 36 00:01:54,690 --> 00:01:57,240 ‫like myMusicians dot size over here 37 00:01:57,240 --> 00:01:59,400 ‫and you, you're gonna get the number 38 00:01:59,400 --> 00:02:03,003 ‫of the current elements inside of your myMusicians list. 39 00:02:03,930 --> 00:02:07,980 ‫So if we run this, you will see that in the musicians 40 00:02:07,980 --> 00:02:12,980 ‫you get four but in mySet you only get one 41 00:02:13,290 --> 00:02:18,180 ‫because you have only James. 42 00:02:18,180 --> 00:02:23,180 ‫Even though you try to add James two times over here, 43 00:02:23,400 --> 00:02:28,400 ‫you couldn't because set only consists of unique elements. 44 00:02:30,060 --> 00:02:34,350 ‫Okay? So there is not much to talk about over here 45 00:02:34,350 --> 00:02:36,960 ‫because it's basically the same thing with ArrayList 46 00:02:36,960 --> 00:02:41,610 ‫but you can only have one value, only one time, 47 00:02:41,610 --> 00:02:44,790 ‫or here it's all unique elements. 48 00:02:44,790 --> 00:02:47,640 ‫So we're going to stop here and we are going to continue 49 00:02:47,640 --> 00:02:50,820 ‫with the HashMap, which is much more commonly used 50 00:02:50,820 --> 00:02:52,953 ‫in under IT application development.