 Welcome back to this video series. Now, let us start with Asset in Collections. The students will be able to learn at the end of this session, students will be able to describe Asset along with various methods and students will be able to write a program using Asset in Collections. If I try to describe Asset, these are some of the important properties related to Asset in Java. First, it is going to work on the principle called as Ashing. Asset is going to work on the principle of Ashing. And second important property is every Asset element is going to be unique. As we have seen in ArrayList and LinkList, they are allowing duplicate elements, but when you come to Asset, it will allow only unique element. Again, Asset allows null values, so null values are allowed here, is non-synchronized again as the ArrayList and LinkList are. Asset does not maintain the insertion order. As we know that in Ashing's concept, the element is going to get stored at a particular bucket value based on Ashing function. And Ashing is well known for its search operation. The time required for searching is minimum in case of Ashing. The initial default capacity of Asset is 16. And again, to create collection, that uses Ashtable for storage. So as we have seen, everything is going to work on the principle of Ashing. And for Ashing, we require Ashtable to store the elements, right? Steps to create Asset. The first step to create Asset is this way, empty, where it is default Asset. You will pass nothing into it. Second way of doing Asset is you are passing some capacity. Let's say you are giving a capacity of 30, 40, 50, n number of elements, whatever you decide. And this capacity can also be changed during runtime. It is not fixed. It is just for understanding or to just to initiate some capacity value. That's it. It is not again compulsory. Third way is giving a capacity and also giving a load factor to it. And the fourth way of creating Asset is passing some another collection as an input to Asset. There might be some another Asset which is already created. And that Asset can be passed as a parameter or as a constructor in this particular fourth way of creating. So total there are four ways of creating an Asset object. Okay. Let us quickly start with the program. We'll come to Eclipse. Let us create one Java file. File, new class file. Java file. Let us create a as demo. Now again, how you are going to create an object of Asset? So it will be Asset H capital S capital type string or any other thing, any other data string set one equal to new Asset. Again, we are going to give you a string. Fine. The next element is to Asset set dot add. So add method is going to, it is not add here. So it is sorry set one dot. Set one dot add. I'll give some elements Ankit. Set one dot add harsh. Set one dot add again. Some name Ruchita. So we have three elements. Fine. Now, if I want to display and check how my output is changing, I can do it through an iterator. So iterator, here we are using a type string. It equal to, sorry, it should be set one dot. We have already seen this in the previous video. Set one dot iterator. By practice, you will come to know how to use iterator. Okay. You have to have and so on. Until and unless, then you won't be able to do it. Okay. So set one dot. Here we will be using a while loop. While it dot as next it dot next. Fine. Let us try to run this program. Ruchita. Now here you can notice one thing. It is not in the way you have inserted. It is random. It is not again random. It is based on the ash value. That ash value is created by the ashing function itself. We are not aware with what ash function it is going exactly using. Okay. No need to understand that thing. But one thing is sure here that it is using some ashing function and the elements are stored according to their ash values. So by the ash values, Ruchita is coming first, Arsh is coming second and Ankit is coming third. Fine. Now likewise, I will be creating one more as set. Asset set two. We'll have let's say I'll remove it on string set two equal to new as set again type string. I'm doing it slowly so that you people follow the same steps while watching the video. I'll give you a temp set two dot add XYZ some random strings I'm putting here set two dot add let's say PQR. Now if I want to copy the complete set one into set two, I can do that set two dot add all add all the elements of set one. So again, I can use this iterator part over here. It will be it one it one dot as next it one dot as here instead of set one. I'll be using set two. Let us see what will be the output now. It is Ruchita Arshankit for first case second case. It is giving him PQR temp Ruchita XYZ Arshankit. You can see there is a mixture of output and we this mixture is getting changed based on the ash value. Again, we have talked one important principle about ash set is that they doesn't allow duplicate elements. Let's say whether they allow duplicate elements or not. Let's remove this Ruchita from here and try to put Ankith once again. So now in our set one we have two Ankiths Ankith Arshankit twice. And when we display this using an iterator, let's see Ankith is getting stored twice or only once run it. Here you can see in output Arshankit that is coming only once in this particular while loop. So what is happening to second Ankith? It is getting ignored. That's the property of as said it doesn't allow duplicate elements. I think this part is clear from this particular set. Okay. Even you can remove in between elements using a method called as remove. So let's say you want to remove some element set two dot remove. We'll remove all the string based on that. If I say Ankith, set two dot remove Ankith. Let's see this line should come after copying set one to set two. Set two dot remove Ankith. Let's see whether it will remove Ankith. Yes, it has removed. So you can see every elements are stored minutely as a separate location. They are not stored in one go. They are stored separately one by one. That's the proof of removing Ankith from this particular list. If you say that remove all, if you just use this method remove all, do we have remove all? No, we have instead of remove all, let us use clear. Set two dot clear. It will clear all the elements present in set two. Let's see Arshankit. Only Arshankit are coming over here. Fine, so everything apart from it has been removed from this particular set two. Everything has been cleared. Likewise, set two dot, when you do set two dot, these are all the methods available in set two. Add, add all, clear. Even you can see the return type available over here. Contains. I want to check whether a particular element is containing or not. If I want to check that, you can do this. Set two dot clear, I'll remove this. Let us remove this iterator also. If set two dot contains, set two dot contains Ankith, we will print Ankith is present. It is saying Ankith is present. If I remove Ankith from here, from add, if I remove Ankith, I need to have a else condition as well. Else, I can say Ankith is not present. Ankith is not present. Let us see what will be the output here. Ankith is not present. I have removed, there is no Ankith in my case. Once I do go here, it is saying that Ankith is not present. This is how we are going to work on collections. The beauty of collections is that you can grow its size to n numbers. If I want to find the size of this particular collection, I can do that set one dot size. Set one dot size is going to return the size of this particular collection. And it is one. Only one element is stored here. And it will increase by the size or the elements you are inserting. The number of elements you are inserting, the size will grow dynamically. There is no as such limit. So your complete memory can be occupied with collections. Let us try to answer this question. How many ways we can initiate an asset? Yes, pause and try to answer it. The answer is four ways. And these are some methods, popular methods used in asset. They are not limited again. Add, clear, contains, split, okay. Split Rater and size. So split Rater is used to fill fast split Rater, laid binding, such kind of operations can be done using split Rater size. As now we have seen that it returns the size of the particular collection. These all methods are there. Apart from this also, there are many other methods which we have seen. So here again, if you want to look at all the collections methods available here, set one dot. These are all the collections available. Methods will notify all, parallel, remove, remove all, size, stream, two string, weight. These are all methods are available inside this particular. And it should be used as per the application requirement. Fine. These are some of the references. Thank you.