 Hi, guys. So in this video, we're going to be discussing multi-dimensional arrays in Java. So a multi-dimensional array is an array of arrays. And it can also be envisioned like so, as a collection holding other collections. So what I've drawn here is a two-dimensional array, or an array of arrays. But we could just as easily have a three-dimensional array, which is an array of arrays of arrays. And we can envision this as a collection of collections, each one of which contains other collections. And while you'll rarely see this, it's possible to have four-dimensional arrays and so on and so on. But for our purposes, we're just going to be focusing on two-dimensional arrays. So let's say we have three one-dimensional arrays. We have array A, array B, and array C. We can create a two-dimensional array, M, like so. So here M is a reference to an instance containing three arrays. And each of these are in turn references to three different instances, B, A, and C, like so. Now let's say I want to access this item in array M. How would I go about doing that? Well, we simply access the array at index one. And within index one, we access the item at index zero. So it's really just an extension of what you already know about accessing items in one-dimensional arrays. Now just note that it's also possible to create multi-dimensional arrays like so, where we declare the multi-dimensional array like this. And then we allocate memory for the outer array and the inner array like so. Now what if we want to, say, traverse over all of the items in M in order to access every single item and set it with a particular value? Well, in order to traverse over every item, we're going to need to use a nested loop. So let's head over to Eclipse now to take a look at how that works. All right. So you can see here we have the same array, two-dimensional array M that we looked at earlier that's built by the three arrays A, B, and C. And then under here, we have this method double values in array, which takes a 2D array and doubles the value of every item within the array. Within each array of the array, you could say. So the way that we're going to access each item within this method is going to be using a nested for loop. So here, we have the outer loop, which is going to loop through each item in the outer array. And then underneath, we have the inner loop, which is going to loop through the inner array in order to access each individual value within each array. So we've called this method on our array M. So let's go ahead and run that through the debugger so that we can take a better look at how it all works and see how multi-dimensional arrays look within the debugger perspective. All right. Okay, so at the start, we have multi-D array, which, of course, is going to just look like M. I'll just open this up so you can see. So you can see here, we have our three arrays, which are, of course, B, A, and C. And then they nested under there, we have the values within each of those arrays. So that's how two-dimensional arrays look within the debugger perspective. But let's step through and start looping through. So if we take a look at our nested loop here, we have for i equals zero i is less than multi-D array dot length i plus plus. So as long as i is less than the length of our array, multi-D array, then we're going to, for each item in the outer loop, loop through our inner loop using j, as long as j is less than multi-D array i dot length. So basically, in other words, for each item in the outer loop, so for each of zero, one, and two, we're going to use the inner loop to loop through the length of each inner array. And then we're going to change, we're going to double each value. So let's just keep moving through here. So we have i zero j zero. So we're going to be accessing this item right here. And you'll see when I step through with this sign here, it's going to double. And then we're going to j plus plus j is going to be plus one. So we're now accessing i zero j one, which is zero one, this item right here is going to be doubled. Now, of course, we've reached the end of our inner loop here. So we're going to exit the inner loop, back to the outer loop. Now i becomes one, j becomes zero. So one zero, we're accessing this item right here. So you can clearly see the pattern here of the order in which items are accessed within our multi-dimensional array using a nested for loop like this. First, we access each array sequentially. And then within that array, we access each item sequentially. So now we can just step through faster and you can see what's happening as I go through each items being doubled. I now equals two, we're accessing the final array. And that's it. And then after this, one more. And then after this, the method will terminate. So that was just a quick look at how to go about using nested for loops to access each item within a multi-dimensional array. And in general, in this video, I hope you got a better idea of how multi-dimensional arrays work. So thank you for watching, and I hope you enjoyed the video. Bye.