hey there everybody so today I'm going to explain 2D arrays in Java also known as multi-dimensional arrays a two-dimensional array is an array where each element is an array it's useful for storing a matrix of data let me give you an example let's say we have some basic one-dimensional arrays I will create a string array of fruits think of some fruit I'll add an apple an orange and a banana then I'll create another separate array let's create a string array of vegetables think of some vegetables I will add a potato an onion and a carrot let's create one more I will create a string array of meats I will add chicken pork beef let's add one more and fish these three arrays are all separate one-dimensional arrays well what if I told you we can make an array made of arrays where each element is an array here's how we're going to combine all these arrays together into a grid or Matrix I will create a two-dimensional array of strings we will need two sets of straight brackets I will name this two-dimensional array groceries and then we need our curly braces this two-dimensional array each element within this two-dimensional array is going to be an array we have fruits vegetables and meats let's attempt to display these elements you can use a for Loop or enhanced for Loop within this for Loop what is the data type of each element well each element is a string array so we need to list the data type as a string array let's give a nickname of each element as Foods in our two-dimensional array of groceries let me show you what happens if I print each element within our two-dimensional array of groceries I will print each array of foods here's what we got well we get a bunch of memory addresses because arrays are a reference data type we're referring to some place in memory we'll need to use a nested Loop and enhanced for Loop would be good for this with each of these arrays what is the data type of each element within each well we're working with strings so the data type is going to be string let's give a nickname of each element as food in our array of foods during each cycle of this Loop let's print not print line each food and then I'll add a space here's what we got currently we have our first array and our second then third after finishing each array I'm going to add a new line character we can use aint line statement for that here's what we got now what we have is a grid or Matrix of data you could say that there's columns and rows each row is a separate array now when initializing an array you don't necessarily need names let's remove fruits copy the elements of this array including the curly braces and paste them within this two-dimensional array just for readability I'm going to place each row on a new line let's replace vegetables with the elements including the curly braces same thing applies with meats and we can delete all this this would work the same groceries is a matrix of data a grid let's print this and that works the same if you ever need to access or change an element you'll need to use two indices for example let's replace apple with a pineapple we will take our two-dimensional array of groceries and list two indices the first index applies to the row the second index applies to the column so we're saying at rows 0 column 0 we can change it or access it let's say that row zero column zero is now a pineapple rather than an apple then we have pineapple orange banana let's replace our potato with something else that would be Row one column zero Row one column zero is now celery celery onion carrot let's replace the carrot with celery then that would be Row one column 2 0 1 2 Row one column two potato onion celery let's replace pork with eggs that would be row two 0 1 2 column 1 0 1 row two column 1 is now eggs we have chicken eggs beef fish to access or modify an element within a 2d array you need to list two indices the first for the row the second for the column okay now we're going to create a mini project we'll create a two-dimensional array that resembles a telephone number pad this two-dimensional array will be made up of characters the data type is Char and then we have two sets of straight brackets let's name this two-dimensional array telephone equals we have an array of arrays we'll have four rows and just for readability I'm going to place each of these on a new line just so it resembles a grid or Matrix for the first row we'll will have 1 2 3 and these are all characters not strings we're using single quotes not double quotes for the second row we'll have four five six the third row will be 7 8 9 now for the last row we'll have an asterisk character zero and pound or hashtag as I like to call it so here's our Matrix our grid of characters we have an array of arrays it has rows and columns now let's display our data we'll need nested Loops for this our outer for Loop is going to be in charge of the rows what is the data type of each element within this two-dimensional array well each row is an array of characters that's going to be the data type of the outer for Loop we have an array of characters let's give a nickname of each inner array as a row in our two-dimensional array of telephone for every Row in our telephone do this then we'll need a nested Loop what is the data type of each element within each array their characters the data type will be Char let's say for every number in each array of row we'll print the following we'll use print rather than print line we'll print each number and I'll add a space character let's do a test run after each row I'm going to print a new line character so when we escape the in four Loop I'll add an empty print line statement and here's our telephone we have rows and columns it's a two-dimensional array of characters so those are two dimensional arrays they're an array where each element is an array it's useful for storing a matrix of data we probably won't be using 2D arrays too often but you should still be familiar with them and well everybody those are two dimensional arrays in Java