00:00Now, let's take a little idea of how an array list is internally implemented in Java.
00:05The array lists are internally implemented in the form of arrays.
00:10So, the array lists are in Java. If we look at the code, which is in-built code.
00:15If you look at it, the array lists are actually an array.
00:19But there are some logic defined in which we can see the dynamic size.
00:24What is the logic in this way?
00:25There are different versions of Java, like Java 8, Java 7.
00:30Everyone has some differences.
00:32But I'm trying to give you a basic overview.
00:35From which we can understand that we are in any Java.
00:37So, what will be the method?
00:39Some specific values will change according to the version.
00:42But the method is almost the same.
00:45In Java, I define the array list.
00:48As I write this line, array list of integers or of string or boolean.
00:56List is equal to new array list.
01:01As I write this line, what happens?
01:05In Java, I have an array.
01:08And this array has a particular size.
01:11In the beginning, it will be fixed size.
01:14It will be fixed size.
01:15It will be fixed size.
01:16It will be fixed size.
01:16It will be fixed size.
01:17By default, I have a 10 size array.
01:20Which I can store in my 10 elements.
01:22And this array is the same.
01:24As I try to access the list,
01:26The list will actually access the array.
01:29And it will be fixed here.
01:32Now, as we are in this list,
01:35We start to fill the elements slowly.
01:38Let's say that I have added 1,
01:40Then I have added 2,
01:41Add 3,
01:42Add 4,
01:42Add 5,
01:43Add 6.
01:44In this way,
01:45You can write in logic that
01:47When the list is filled,
01:49It means completely filled.
01:51Or when the list is half filled.
01:55I mean internally made an array.
01:58The list and the array are the same.
02:02Internally, an array list is the same.
02:05As this list is filled,
02:06It means completely filled.
02:08So, what does Java internally do?
02:10Java internally,
02:12It will make another array of double size.
02:15It will make an array of double size.
02:17It will make an array automatically.
02:19We will not tell Java,
02:20It will make an array of double size.
02:21It is filled.
02:22Because we will not know that
02:23The array list is filled.
02:25So, internally,
02:25Java will detect the array inside.
02:28So, it will make an array of double size.
02:31It will make an array of double size.
02:31In which,
02:32It will copy all the elements.
02:35So, 1 will come,
02:362 will come,
02:363 will come,
02:374 will come,
02:375 will come,
02:386 will come.
02:39And the other elements will be copied.
02:41So, if the size was 10,
02:43Now, the size will be 20.
02:44If we think that the size is also filled,
02:47Then it will be 40.
02:47It will be 40.
02:48If it它 has even 40,
02:49Then it will be 80.
02:51We will have 80.
02:51If it has even 80,
02:52Then it will be 160.
02:54So, every time this is double.
02:56It's possible that it will be down in Java,
02:57In any Java version,
02:58It will increase 0.5 times.
03:00So, it is first 10,
03:01Then then it will be 15.
03:02If it was 15,
03:03Then we will add 7.5 times.
03:06I think it will be 22.5.
03:08So, it will increase.
03:09It will also be 1.5 times.
03:12Here, I have 2 times.
03:13What is the logic?
03:14The logic is that
03:15As I have defined an array list
03:17which is defined in java, which is defined as a fixed size
03:22then as I add elements in my list
03:26all the elements start my internal array
03:30now as my internal array will be filled
03:32what will happen? java will automatically be filled and detect
03:36and the double size array will be made
03:39now the old elements will copy
03:43and the new elements will be stored here
03:48and the double will be filled
03:51and the double will be filled
03:53and what will happen with the old fixed array size
03:56will be deleted from memory
03:58when I have a 40 size, the 20 will be deleted from memory
04:02so in this way, arraylist is implemented internally in java