 Hi guys. So today, we're going to be getting an introduction to custom-built array lists by exploring how we can grow an array in Java. Now, as we know, in Java, an array is of a fixed size. So once we declare an array of a particular size, we can't simply increase its size by adding additional items to the array. In addition, prior to specifying values for the array, our array is filled with a default value depending on the array's type. So an integer array is prefilled with zeros, a boolean array is prefilled with false, and an object array is prefilled with null. So we can see this using an example. So here we have declared an integer array of size 5. We've then set the first index of the array to equal 10, and when we print this array out, we can see that the first index is indeed set to 10, and then the additional indexes are set to the default value of zero. So this is really useful to keep in mind, because often we do want to populate our arrays dynamically, one value at a time, rather than statically initializing an array upfront. Alright, so what can we do when we're not really sure how many values are eventually going to be stored in our array? So in other words, we don't actually know how large we need our array to be. Well, let's take a look. So you can see here we've declared an integer array data with an initial size of 2. Now first of all, we're going to want a way to keep track of the number of values stored in data. So what we can do is use a counter. Now in this example, our counter is called nItems and each time we add an item to data, we want to increase nItems by one. Now because we're keeping track of the number of values stored in our array with nItems, we can find out if our array is full by checking if nItems equals data.length. And what should we do if our array is full? Well, perhaps we can find out with some help from our friend, the Hermit Crab. Hermit crabs use abandoned seashells as mobile homes. As a crab grows, its shell becomes an ever tighter fit. So eventually a crab needs to move in to a bigger one. So when our array is full, we're like the Hermit crab with a shell that's too tight. He needs to find a bigger shell and we need to create a bigger array. Now we can do that like so by creating a new temporary array and setting its length to be larger than that of our original data array. Now it's all good and well for the Hermit crab to find a new larger shell, but he still needs to move into the shell. And likewise, we need to move all of our values from data into our new array temp. And we can do that like so with the for loop, setting each index of temp to equal the value of that same index in data. Now the Hermit crab is all moved into his new shell, but he still needs to make that new shell feel like Herm. And likewise, we need to make our temp array into our data array. So how can we do that? Well, we can re-reference our array data to refer to the new larger array instance temp by simply saying data equals temp. Okay, so putting it all together, we have our integer array data, which has an initial size of two. We have n items, which is our counter to keep track of how many items are stored in data. Now we're going to add a total of 10 items to data. And each time we add an item, we're going to check to see if the array is full by checking if n items is greater than or equal to data dot length. If the array is full, then we're going to grow the array first by creating a temporary array that has room for three more items than does the original array. We're then going to move every item from data into our new temp array. And we're then going to re-reference data to refer to the same array instance as temp. So each time we add an item and we're just going to add a random number each time to the array, we're going to increase n items by one to reflect the additional item that is now in data. So let's go ahead and run this program so we can see what these print statements give us. Alright, so first of all we have this reference indicator. And this is hash code that just shows us the reference of the array. So at first our array data just has one single value. When we add another item to it, it now has two values and the reference stays the same. However, when we add a third item to data, we grow the array as is indicated here. And then the reference indicator changes because we have changed data to refer, or rather we've re-referenced data to refer to the new temp array that we've created. So now data has a new reference and it has room for three more values. So you can see now data has three values, now four values, and now five values. But if we want to add a sixth value, we again need to grow the array. So we grow the array and once again we can see the reference indicator changes. Data now has six values, seven values, eight values. And now once again if we want to add a ninth value, we'll need to grow the array. The reference indicator again changes. We now have an array that has nine values, ten values, and then that's the end. So that was just a little introduction into a custom array list by having a look at how we can grow arrays in Java. So I hope you guys found this helpful and thank you for watching.