Java ArrayList Program | Java ArrayList tutorial | Java Collections

Hi friends, this is Rakesh from Let’s make learning simple channel. Now we are going to see.. about arraylist. So basically what is arraylist? Arraylist is a class that implements listed effect. So, this is the arraylist. So this arraylist is an inbuilt library that was provided by Java. So arraylist implements list. So basically here are angular brackets and inside that is E alphabet. It implies that arraylist is a generic class. Basically generic class. Whatever the data type.. that you send in the generic class then it will act as that data type object. Example, here “Arraylist” So what it does is, the books will treat it as a arraylist of string objects. If suppose if you send integer, how it will be treated as? Array list of integer objects. If you send the float means arraylist of float objects. So now we’ll see how arraylist methods are used. So first initially what we are trying to do is, “books.size”. Initially there is not data present in the books so books size, the size would return 0. And then what we have done is we have added C, C++, Java. Suppose in this statement we have added C so, C would be present at 0th position. And then we have added C++. So C would be present at 0th position. C++ would be present at 1st position. And then we have added Java. C 0th position, C++ 1st position, Java 2nd position. So what “add” method implies is, so whenever we add an element without any index, so it will add at the end of the list. So here, 0, 01, 012. And the we are trying to print the size. Initially books size would be 0 now it would be 3. So if suppose if you run this thing, you’d see 0, 3, C, C++, Java. And then what we are trying to do i, we are trying to add a Python” at index position 1. So, initially this should be the case. C at 0th position, C++ at 1st position, Java at 2nd position. Here, we are trying to add python at the first position. So, there won’t be any change in the C position, because C is present at the 0th position. Python would be added in the 1st position. So C++ will be moved from 1st to 2nd. Java would be moved from 2nd to 3rd. So this is the new list. So now if we run this thing, we would see that C, Python, C++, Java. And then what we have done is, we are trying to remove the C object or C data from books. So, this is the existing case. C at 0, Python at 1st and C++ 2nd and Java 3rd. So if suppose, if you remove C, then the C would be removed from the 0th index. Python would be moved from 1st to 0th index, C++ from 2nd to 1st, Java from 3rd to 2nd. So, this would be the, result of that list. So, if suppose if you run this thing. Now we would see that Python, C++, Java. So this is the basic example of how arraylist can be used in Java. We will talk more about linkedlist and related content in the upcoming video. So thanks for watching. Now here you will see the channel icon, please click on that for subscribing the channel.

Leave a Reply

Your email address will not be published. Required fields are marked *