 Hello everyone. So, I am Professor Tattadri Gandmal from Valchand Institute of Technology, Solapur. In this video, we are going to see ash table in collections. So, till now in collections, we have seen a lot of varieties like we have seen arialist, stack, Q, etc. right. So, now moving on to next important collection type is ash table. So, what exactly we are going to learn? The learning outcome of this video will be a student will be able to describe ash table along with various methods. So, we have met lot of methods in every collection. So, we are going to explore them. Second is student will be able to write a program using ash table in collection. So, we will have a short demonstration on how to write a ash table program and we will try to learn out of it. Okay. Now, coming to ash table, what is ash table and why it is required? Ash table stores items as key value pairs. Okay. So, till now we have seen that arialist stores only one item, one, we can say one entry we have in arialist or we can say stack or Q. But when we come to ash table, we need to enter key and value pairs. Okay. So, it will take two parameters as an input key and value. I'll come back to it later. Each item in the ash table is uniquely identified by its key. So, key is unique value can change and key will also change but key should be unique. You cannot have a repeated key element. Okay. Therefore, we name it as key in an object. So, they are stored as an object type. So, everything you put it in as a key value pair that will be stored as an object. Okay. So, mostly string class is popular, but it is not restricted. Okay. You can use any data type for storing ash table or any object type to store into the ash table, but mostly strings are used. Okay. Now, what are the steps to create ash table? An ash table can be constructed in this manner. Ash table ht equal to new ash table. This is blank entry of ash table. Okay. This only object is created at ht without passing any parameter over here. This is simplest way to create object of ash table. Ht can be anything. Another way to specify is giving some capacity, rough capacity here. I'm giving the capacity as 12. It can be anything. But remember that whatever value we are going to give it here, it is not going to restrict in any manner. That means even if I'm specifying it as 12, I can enter more than 12 elements. I can enter less than 12 elements. I can enter 12 elements irrespective of what value I am specifying. This is only for users, perseverance like, okay, I'm going, my ash table is not going to be more than 12. It's just for perseverance. Later it may increase to any stage. So with that flexibility, we have with collections. Now coming to program, shall we do a simple program on ash table? Okay. Now for doing this, we will come to sharp developer. Okay. So the procedure to start with is I'll tell you from the beginning file new solution. Okay. Sharp Windows application console application give the name as a demo ash. I'll give it as demo ash can be anything. Now this program is created. I'll delete this comment part for ease of understanding. Okay. Now, as we have seen earlier that one namespace which is required for collections is system using system dot collections. This is very important. Okay. One and then and then only we will be able to create its object and use its method. So here I'll be using ash table ash table ht equal to new ash table. So first procedure we have seen is that empty. Let us try with empty one. Okay. Now if I want to add an element to ash table, it will be ht.add. Here I'll be adding two parameters. One is the key and another is its value at 10. Let us assume that we have such in ht.add. I'll enter one more key. Let us give the key as seven and I'll write it as dony. Okay. Likewise, I can put ht.add. We'll have 18 and I guess it is right. Numbers are right. Coley irrespective of that, but still I'm following. Okay. So such in 10, 7 and 18. Okay. This is how I'll be. I'm inserting three elements. Here 10 is the key and such in is the value. Okay. So key should be unique as per the definition of ash table value can be repeated. Okay. For example, I can write ht.add 18 with another I can write it like this, but here there will be an error saying that repeated key 18 is getting repeated here. So key can change. So if I make it 27 and I write here instead of Zaire, Coley, this is fine. Value can be repeated, but key should not be repeated. Okay. This is acceptable. This is how ash table stores the values. Okay. Now if I want to print it, I'll be using a for each loop for each int I in what ht. I need to specify where we whether you want to print the key or whether you want to print the values. So it depends. I'll be printing keys. Okay. So here I'll be printing I this is how I'll be inserting elements into ash table. Okay. Okay. I hope it is pretty clear from it. Let us check whether we are doing it right or wrong. Yes, exactly right. 18, 10 and 7 is getting printed. So the way I have added it and we have printed it. That's it. If I want to print values, I'll be using one more for each loop for each int J in ht.values. Okay. So I can have this once again. Instead of five here it will be J. Now the values will be printed instead of keys here in the second for loop. So in my console screen, just a minute ht.keys here. Okay. The type is string here. I am taking it as integer. It should be of type string. Okay. String J in this part. Okay. 18, 10, 7, Koli, Sachin and Dhoni. Okay. This is how it is getting printed. Fine. Now what else methods we have here? Let us see ht. There is a clear, there is a clone contains contains key. So I can check whether if a particular element is contains or not ht.contains. I can check whether Sachin is present in it or not. So it will be, obviously it will return a Boolean value that is true or false. Okay. Likewise, I can play with all these readyment methods which are there in collection. That is the biggest advantage of using collections. You have all these methods readily available. You can remove a particular element. You can convert it to two string particular string. You can check it's equal or not. So you can clone it. You can clear the every collection which we have created. So all these methods are present inside it. Okay. Let us come to our presentation. There is a small question for you people. How items are identified in Ashtable? Okay. You can take a pause and answer it. The answer for this is using key. As I said, key is unique in collections. Every collection item is identified by its key. So keys are very, very important. I hope you have answered it rightly. Now methods in Ashtable. These are some popular methods not limited to, but mostly used, most frequently used method for Ashtable. Add. This is, we have just now seen it that how to add an element into Ashtable. Remove. You can name a specific element with its key and you can remove it. So removing will be on key basis. Why? Because keys are unique. That's what is making it different. Second is clear. Next is clear. Clear means everything will be removed. All elements from Ashtable will be removed. Contents is to check. As I said, specific element is present or not. That again we do it with a specific key. So keys are very, very important. Values are just data which is stored at that particular location. You can take it in that way. Okay. Get Asht returns the Asht code of a specific key. So every object in C Asht is having an Asht code and that Asht code can be obtained by using a method called as Get Asht. Okay. These are some of the references which I have used. And one more thing I forgot here is we can also ht.containsKey. There are two methods. Contains and containsKey. What is the difference between contains and containsKey? We can explore them also. ContainsKey. Whether it contains a particular key. So I can say here containsKey10. I can make it into an if. If ht.containsKey10, it is going to return a true or false. If it is containing, I will do some activity. Otherwise not. This we can do with this method. Also ht. You can also remove a particular element. Here you can see that it is saying that objectKey. We need to specify a key. So let's say I will remove 7. ht.remove7 should remove Dhoni from the list. Okay. Now if I print this for each loop once again after removing, it should not have Dhoni in the list. Okay. So first time this 18, 10, 7, Koli Sachin Dhoni is getting printed. And after removing, I am printing 18, 10, 7 is not there. And Dhoni is not there. So this is how we can remove an element from ash table. Okay. That's it from this video. I hope you have understood it. Okay. Thank you.