 Hello friends. I am Sanjay Gupta. I welcome you on my channel. You can watch various programming related videos on my channel. So you can search it. You can subscribe it for updates. It contains more than 800 videos. You can also type the keyword programming by Sanjay Gupta on YouTube to watch these videos. In this video, I am going to demonstrate you how you can declare 2D array with different column size in Java. So for example, if I write this, you might have used this declaration in C and C++. It means there will be 3 rows with 3 columns in each row. It means column size for each row will be same. But in case of Java, you can have different column sizes for each row. So let's start. First, I am going to define a class. Inside this class, I am going to define main method. Inside this main method, I will be declaring 2D array with different column sizes. So this is the initial declaration. Here you can see I have declared only row number. So this array will be containing 3 rows. Now, first row that will be having 0th index will be containing 5 columns. Second row will be containing 3 columns and third row will be containing 7 columns. So row size is 3 and column size is different for each row. Now, in case of Java, whenever we declare integer array, whether it is 1D array or it is 2D array, it automatically initializes with default value that is 0. So I am not going to assign any value to this 2D array. I am just going to print this 2D array so that you can visualize whether these different column sizes are available or not. Later on, you can receive these values from user for calculation purpose. So now here I am using length attribute so that I can find out rows and column quantities for this 2D array. So if I am writing ARR.length, it means it will provide row size. Here ARR.length is providing row size. Inside this for loop, I am going to use another for loop because this is 2D array so I have to print a different rows. So nested looping is required here. Here watch carefully the condition. Watch this condition which is available in second loop. J less than ARR of I.length. So this J loop will be repeating based on this condition. So in 2D array, each row is having different column size. So that column size will be provided this ARR.length. So I is providing row index and that row index column size will be provided using this length attribute. So this way we can process 2D array having different column sizes in Java. This feature is not available in C and C++ because there is no length attribute available. So that's why in case of C and C++ we have to use same column size for each row. So I hope you have understood whatever I am going to explain in this video. So here ARR.length is providing column size. Now inside this loop I am going to display values using ARR of IJ. And I am going to use tab so that sorry you can read values properly. This will be system.print. Then again system.out.println. This is because after printing one row cursor will move to new line. So this way I have implemented the complete code in front of you. Now I am going to compile it first and then I will be executing. You can see it is showing three rows. In first row you can count number of zeros, five. In second row three, in third row seven. And see here in first row we provided five as column size. In second row we provided three and in third row we provided seven. So this way you can have a 2D array with different column size in Java. So I hope you have understood how we can use this. This time I have used the default values. Now if you want to receive values from user then also you can use this logic. You just have to remember that whenever you are repeating the loop you have to use ARR.length for row size and ARR of I.length for column size. So if you are using this length attribute for finding out the row and column size then your process will be okay. Otherwise you cannot handle this kind of situation to fill each row with different column size. So try that at your own. I hope you have understood whatever I have explained in this video. If you want to watch new programming related videos you can search the keyword on YouTube that is programming by Sanjay Gupta. Thank you for watching this video.