 Hi guys, so today we're going to be looking at how ArrayLists are stored in memory. So first of all, it's important to note that ArrayLists hold objects, not primitive data types such as int or char. So for example, if we want to create a new ArrayList to hold integers, we need to use the integer object type with the capital I rather than using the primitive data type int. So here we have iList, which is an ArrayList of integers. And underneath, we've added four items to iList using the ArrayList add method, which just adds items to the end of the list. And we then display the list here. So if I run this, we can see that iList contains four items, 10, 70, 20, and 90, just as we've added here. Now, if I put this in the debugger, then we can take a look at what's going on underneath the hood in the memory. So here we have iList, it's of type ArrayList. And if we expand this, we can see iList contains four objects, and each object refers to an instance of integer. So as an example, if we expand object zero, we can see that it refers to an integer object with an instance variable value of 10. If we expand object one, we can similarly see that it refers to an integer object with an instance variable value of 70. So moving on to our second example, here we have the rectangle class, which we'll be using for this example. If we go back to the client and just take a look at this section of code, then we can see here we have a new ArrayList that holds rectangle objects. And underneath, we have two different methods for adding objects to the array. So first of all, we can create a new rectangle object like Sir. So here we've created a new rectangle called R1 with a width of five and a height of two. We can then add a new rectangle objects to our ArrayList using the add method from above. Alternatively, we can actually create a new rectangle inside of the add method like Sir. So here we've created a new rectangle with a width of seven and a height of five. Now, if we pop this through the debugger, we can see here that we have two rectangle objects, R1 and R2, each with a distinct ID of 30 and 32 respectively. Now, if we expand our list, we can see actually that object zero in our list refers to the exact same instance of rectangle as R1. And likewise, object one in our list refers to the same instance of rectangle as R2. And we can see this easily because the IDs are the same. So we can see object zero in our list has an ID of 30 as does R1. And similarly, object one in our list has an ID of 32 as does R2. All right, so moving on to our final example, what we have here is a new ArrayList mega list, which is an ArrayList of ArrayLists of integer objects. And what we've done underneath is we've added iList to megaList. iList was the original integer ArrayList that we created above. We've then created a new ArrayList, iList2. We've added three values to iList2. And we've then added iList2 to megaList. So megaList now contains two ArrayLists, iList and iList2. Now, if we take a look at this in the debugger, we'll see that megaList, if we expand this, contains two objects, zero and one with IDs of 19 and 34. Now we can see that iList also contains an ID, sorry, has an ID of 19. And iList2 refers to an ArrayList with an ID of 34. So once again, we can see that object zero in megaList refers to the same instance of ArrayList as iList and object one refers to the same instance as iList2. We can also expand this further. If we expand object one in megaList, we can see that object zero refers to an instance of an integer object with an ID of 38. Likewise, if we expand iList2, object zero in iList2 refers to an integer object with an ID again of 38. So both object zero here and object zero here refer to the same instance of an integer object. In this case, it's the object that we added right here. You can see with a value of 60. So that's how ArrayLists are stored in memory. Thank you guys for watching and I hope you found this helpful.