 So, welcome back to the video. In this video, we are going to see ArrayList in collections. I am Professor Dattadri Gandmal, working in Walter Institute of Technology, Solapur. So, what we are going to see? At the end of the course, student will be able to describe ArrayList along with various methods. ArrayList is a collection in that we have various methods. So, student will be able to describe all those methods. Second, write a program using ArrayList. So, student will be able to write a simple program using ArrayList. We can write n number of programs using ArrayList. We will see some simple approaches to write ArrayList. So, this is the motivation behind it. So, to describe the ArrayList and to write a program using ArrayList. ArrayList, what is ArrayList? ArrayList is similar to Array, but there is a slight difference between Array and ArrayList. In Array, we know that the size is fixed. Whereas in ArrayList, we can increase the size as and when required. That is, ArrayList grows dynamically on the elements. So, as elements are inserted, ArrayList size will be increased. And as number of elements are decreased, the size decreases. So, there is a variation in it. So, namespace is system.collections. Using system.collections is the namespace under which ArrayList is listed. And we don't need to specify the size initially. So, even if you specify, it doesn't matter. So, we can even do that, but there is no meaning for it. Next, ArrayList adjusts the capacity of the array as the number of elements increases or decreases. As I said, during runtime, if you want to insert 100 elements and you have defined the size as 20. So, those 100 elements can be inserted using ArrayList. It will not say that size is full. It will grow its size dynamically. Even you reduce number of elements, the size will get adjusted to the ArrayList size. Size is calculated based on total number of elements present in the ArrayList. So, let's say I have defined the size as 20. And I have inserted only 10 elements. So, size of ArrayList is not 20, it is 10. So, size is basically number of elements inserted into the ArrayList. So, this has to be very clear. Okay. I hope this slide gives a basic introduction about ArrayList. Now, what are the steps to create an ArrayList? We have a variety of ways to create an ArrayList. First, let us check. It's a simple way ArrayList AL equal to new ArrayList. Here, ArrayList is the class name. AL is the object name equal to new ArrayList again the class name. So, this new ArrayList object is created and the name of that object is AL. Here, we are giving it as AL. You can give anything. So, this is a simple way to create an ArrayList. Another way, here we will specify the size. ArrayList AL equal to new ArrayList 20. So, it's up to you whether to give it or not. So, as I said, it doesn't matter. So, basically, we can give it. There is no error and no wrong with it. ArrayList with some other collections by passing collections in the constructor. So, ArrayList can also take some other collection object as well. So, once I create an ArrayList AL, there are two ArrayLists. Suppose, there are AL1 and AL2. In AL2, I can pass AL1, ArrayList as it is. Let's say AL1 is having 10 elements and AL2 is having 5 elements. So, if I copy AL1 into AL2, AL2 will become size of 15. So, I can have this privilege to copy all ArrayList into another ArrayList. Now, let us have a simple outlook of how to write a program using this ArrayList. So, for this demo, I'll be using Sharp Develop. So, come to Sharp Develop. This is already open. So, I will close this particular project. I don't require this. Let us close. Let us begin from start. So, file new. We'll go down to solution, click on console and give the file name. What will be the file name? Let's give collection demo. I have given it as collection demo. Okay. Create. The file will be created, collection demo. This is a .csharp file. Okay. And this by default code comes. This is command when it is created, not required. I'll delete it. Just for avoiding confusion, you can keep it as it is. Okay. Now, namespace collection demo. So, namespace is created by the file name. Okay. Inside it, we have a class program that is fixed. So, class program will be there. Inside it, we have a main program, public static void main string ARGS. So, this is standard way. After it, we can begin our program inside main. Okay. Let us try to execute this simple program which already automatically given by csharp. If I execute it, I'm getting the output as allow world. Press any key to continue. So, what exactly this program is doing? Console dot write line, displays on the console and read line will wait till I press a key. Read key. Okay. So, I will remove this and we will start with ArrayList. Okay. So, as I said, ArrayList, header for ArrayList. First of all, we'll let us add namespace. So, ArrayList is using system.collections. This header file is required using system.collection namespace. We call it as namespace in csharp. So, ArrayList AL equal to new ArrayList. I will keep it blank. Okay. ArrayList is created. Now, if I want to insert element into ArrayList, that can be done using different methods inside ArrayList. We will see down to the methods later. So, ArrayList add, let's say I want to add 10. 10 is added. ArrayList.add, let's say I want to add 20. 20 will get added. ArrayList.add, ArrayList.add, let's say I want to add 15. Okay. Now, if I want to check whether they are inserted correctly or not, I will use a for each loop for this. For each loop says that variable element in collection. So, what is the variable type here? We know that it is of type integer element in collection. Which collection? What is object here? AL. So, make it AL. Okay. I hope you're following. Now, if I want to display all the elements in ArrayList, I will simply write a console.writeLine and give element as a object. Int element in AL will scroll down all the elements in ArrayList. Okay. It looks fine. Now, if you can see the output 10, 20, 15, it is giving me the right output. Okay. This way I can write a program using ArrayList. Similarly, as I said, if I want to mention some size, let's say I'll make the sizes 20 and try to execute it, it doesn't matter. So, giving me the same output, even if you mention or don't mention, it is not changing the output. Let's say I will give the sizes two. And we know that we are inserting three elements. Let's see whether it will give an error. It is working fine. So, that's that's what I said. It will grow dynamically as elements are inserted. So, size is absolute. It is, it's up to you. If you are aware how many elements are going to be inserted, you can give the size. Otherwise, leave it blank. Okay. I hope you are following. Now, come down to the PPT. Now here, I have a small question for you people. How many ways can we initiate collections? Just now we have seen there are multiple ways to initiate collections. So, can you recollect? Okay. You can take a pause here and recollect the video and give the answer. So, answer for this question is three ways. In three ways, we have seen empty first one. We are not specifying any size. Second one, we are specifying the size. And third one, we are passing some other collection object to it. Okay. So, there are all three ways to do this. Moving ahead, in ArrayList, we have variety of methods. These are few methods inside ArrayList. So, we have already seen add method. So, add is going to add a particular element into my ArrayList. So, these methods are required to insert, delete, update all values into my ArrayList. Okay. Now add range, add method, add single element. This we have already seen how many, how we can add an element. Okay. Insert, insert an element, remove all sort, sorts the ArrayList, reverse the content of ArrayList. So, the name itself reveals what that method is going to do. Let us check this sort method. I'll apply, how to apply the object dot sort, AL dot sort. Let us check whether it will sort the ArrayList. So, 10, 15, 20. Before this, we were getting 10, 20, 15. Now I'm getting 10, 15 and 20. This is how it is changing. So, this is how we can use the methods of ArrayList. We have a variety of other methods. AL dot copy2. Copy2 will copy the content of one ArrayList to another ArrayList. So, AL dot, we have many more methods like we can put a dot and you will be listed all the methods here. So, equals is there, get range, get type, insert. If you want to insert at a particular position, you can do it with insert. Remove at, remove, you want to remove an element, let's say I want to remove 15. AL dot remove 15. Now let us check the output for 10, 20 is only value which we are getting. Okay. So, I hope you understood the ArrayList. So, these are some of the references which I have referred. You can follow them. Okay. Thank you.