Podcast Lookup

Java Arrays Explained | Declaration, Initialization, Traversal & Introduction to Strings

The Java Developers Hub

  • December 3, 2026
  • 1 h 47 min
  • Episode 14
Episode page
About this episodeArrays are essential data structures in Java that allow developers to store multiple values of the same data type in a single variable…
Arrays are essential data structures in Java that allow developers to store multiple values of the same data type in a single variable. Instead of declaring separate variables for every value, arrays provide an organised way to manage and process collections of data.In this episode, you'll learn the fundamentals of Java arrays, including how to declare, initialise, access, and traverse array elements. We'll also introduce Java Strings and explain how they are used to store and manipulate text.Whether you're a beginner learning Java programming or preparing to work with more advanced data structures, this tutorial will give you a strong foundation in handling collections of data.What You'll Learn
  • Understanding arrays and why they are important in Java.

  • How to declare Java arrays.

  • Different ways to initialise arrays.

  • Accessing array elements using indexes.

  • Understanding zero-based array indexing.

  • Traversing arrays using for and for-each loops.

  • Updating and modifying array elements.

  • Finding the length of an array using the length property.

  • Understanding common array errors and ArrayIndexOutOfBoundsException.

  • Introduction to Java Strings.

  • Declaring and initialising String variables.

  • Understanding the difference between arrays and Strings.

  • Practical examples of working with arrays and text.

Who Should Watch?
  • Beginners learning Java programming.

  • Computer science and software engineering students.

  • Developers strengthening their Java fundamentals.

  • Students preparing for Java programming examinations.

  • Anyone interested in learning data structures and managing collections of information.

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Java Arrays Explained | Declaration, Initialization, Traversal & Introduction to Strings

00:00—
  1. Speaker 1

    Yes, so let's start. Welcome back Coder Army to our Java series. And today we are going to start with a new topic, Arrays and Strings. Now this topic is very simple and if you come from any other programming language, then you will know what arrays and strings are. And if you are new to this topic, then it's okay. We will understand it well and basically and everything will be crystal clear to you.

  2. Speaker 2

    So let's go to the screen and start.

  3. Speaker 1

    Yes, so we are going to see what arrays are. Now any programming language has an interesting topic of arrays. So let's see it from the starting. You will enjoy it a lot. Let's suppose you want to write a program in Java and you want to store the role numbers of students in it. So I will make an integer variable And I can store a student's roll number in it And we will give a value to it Let's say a student has a roll number of 1 I want to store a roll number of 4 students We will need 4 variables I will make one more variable Let's say roll number 2 Let's call it roll number 1 equal to, let's say whatever new roll number will be, let's say its roll number will be 2. Similarly, I will make one more end roll number. Let's say this time the roll number will be 3.

  4. Speaker 2

    And so on.

  5. Speaker 1

    Like this, I will keep on declaring their roll numbers. And I will have all their roll numbers stored. But you think, is this an optimized way? Like this, if I have 100 students. So, will I make 100 variables like this? And I will declare all their roll numbers one by one. Right?

  6. Speaker 2

    So, this is a little problem.

  7. Speaker 1

    And to solve this, every programming language brings a concept.

  8. Speaker 2

    Like we call arrays. Okay? What are arrays? They are nothing.

  9. Speaker 1

    If you were making one variable, then what would have happened? A variable would have been made in memory, let's say, role number 1, and you would have assigned 1 to it. Another variable would have been made, let's say, role number 2, and you would have assigned 2 to it.

  10. Speaker 2

    And it would have been running like this.

  11. Speaker 1

    Why are you allocating different memory? What if I allocate a big memory like this and divide it into sections? First section is to store roll number 1, second roll number 2, third roll number 3, fourth roll number 4 and so on. I allocate a big chunk of memory which I call contiguous memory. Contiguous means 7th memory. One after the other. So if this memory location is 0, then it will be 1, 2, 3, 4, 5, and so on. I will allocate such a memory, and you can add the first child's row number, second child's, third child's, fourth child's, and so on.

  12. Speaker 2

    Right?

  13. Speaker 1

    So this is a very interesting concept. And this is the concept that we have, arrays.

  14. Speaker 2

    Okay? So let's see about this.

  15. Speaker 1

    First of all, like we declare a variable in our programming, we have to declare an array as well.

  16. Speaker 2

    And how do we declare an array? Look, I will tell you about that.

  17. Speaker 1

    To declare any type of array, you first write the type of array. Now you are telling us that the array we are going to declare in a memory, which we call contiguous memory location, will have every element of an integer type. Basically, this array is an integer array. It will store integers. For example, roll number 1, 2, 3. These are integers. So, I have to make.

  18. Speaker 2

    An array of these three.

  19. Speaker 1

    Consider an array as a collection. I have to make a collection of these three. So, the first one is detribe. After this, we will make a curly bracket. Sorry, we will make square brackets. This square bracket denotes that we are going to make an array. Because if you would have written normal int, it would have been of int variable. If we put square brackets in it, then we will understand or the compiler will understand that we are going to declare an array.

  20. Speaker 2

    So after that comes a square bracket.

  21. Speaker 1

    After that comes what name you are going to name this array.

  22. Speaker 2

    Let's say I name it role. Numbers. Okay. So you write the name of this array. Roll numbers. After that you call it. Semicolon. Okay.

  23. Speaker 1

    So in this way. You declare an array. What does it mean to say? You tell the compiler. That we are going to make a collection. Of roll numbers. Let's say something like this. What will I call this?

  24. Speaker 2

    Roll.

  25. Speaker 1

    Numbers and every element in this collection all these elements will be of integer type meaning we will store an integer now see why do we have to tell the compiler that we have to make an integer array and then its name meaning why can't we make an array normally why do we have to tell that it will be of integer type now simply understand this you did here that you told the compiler that we have to Collection, we are going to make an array in which all these elements will be of integer type. The way you told us, why did you tell us? It's a simple thing, we have discussed about it. Imagine that this is your one memory, this is your computer's memory. What will happen in this memory? Whenever you declare a variable, let's say you declare this variable as rule number 1. So what will happen? First of all, a container will be created. Now here is an integer type variable, so it will be a 32-bit container.

  26. Speaker 2

    32 bits, you know.

  27. Speaker 1

    So 32 bits, it has allocated the memory for you. And it will say, you can put any value in this memory. So you put here, let's say 1. Something like this. Now, When you are going to make an array, roll numbers, then it should also know how much memory I have to allocate. Although we have just declared it, not defined it. Now we will define it too. But let me tell you a little bit that the computer should already know how much memory I have to allocate, how much memory I have to store or how much memory I have to occupy to store your roll numbers. So suppose you have to put 3 elements in this array. You have to put row number 1, row number 2, row number 3. Like we put it above. I will tell you the syntax of how we put it. But suppose you have to put 3 elements in this array. And I said that every element is an integer. So you have to put 3 elements and every element is an integer. So you know that first of all you will need 3 cells of 30 to 32 bits. Like here you took 1 of 32 bits. Here you will need 3 of 30 to 32 bits. So this way our compiler knows how much memory we have to allocate to store our values. So here I can store the row numbers. 1, 2, 3. Something like this. And this is the whole concept of arrays. So if I say in the normal language, what is arrays?

  28. Speaker 2

    Arrays is nothing.

  29. Speaker 1

    If I write it a little, arrays is nothing. Collections are of a particular data type of a data type like I have made an integer collection here I have made a collection of a row number and every row number is an integer so there are collections of a particular data type now in that collection we can store multiple values like I have stored row number 1,2,3 separately I can store them together here 1,2,3 like I have shown you here so now let's see here I have declared this variable this is the variable declaration.

  30. Speaker 2

    Claration.

  31. Speaker 1

    Absolutely correct. Now how do we define it? So its syntax is a little different. Now you might have to understand one or two things in this definition. But it's okay, we'll study it in depth later. But now you just have to understand how do we declare. So you write int, bracket, roll numbers, whatever is the name of your array.

  32. Speaker 2

    This is the name of your array. Equal to.

  33. Speaker 1

    Now look at this carefully. You write a special keyword whose name is new. You wrote the keyword as new. After that you write int again. And make square brackets. And close it. And there will be one more thing in the square brackets. Let's say I write 3 for now. And what does this 3 tell? This 3 tells size. Size of your array.

  34. Speaker 2

    Okay. Now let's define everything one by one. Okay. First of all. I told you. This is data type. Of array. You know this. It tells you what is the data type of array. This is identifier. Name. You can also call it name of array. Okay.

  35. Speaker 1

    Now this is a special keyword. This is a special keyword. Let me write it. Special keyword.

  36. Speaker 2

    Now why is it used? This is used to allocate memory. In heap.

  37. Speaker 1

    Now, obviously, many people don't know what heap memory is, right? So, we will study all that later. When we have studied objects and classes, then we will understand about memories and understand what a new keyword is. But for now, let's assume, again, like a black box, that we have to write a new keyword. Now, finally, we will tell int3. Here, we will tell size of array. Okay, so I hope you have understood everything that how we did the declaration. Okay, by combining all these, your one array is defined.

  38. Speaker 2

    This is called definition. Definition.

  39. Speaker 1

    Like you define a variable, means if you want to declare a variable, then you write int x, right? If you want to define it, then you write x equal to 4, right? In the same way, if you want to define an array, just declare it, then you just write like this, roll number, And if we want to define it, then the role number is equal to new and int and its size.

  40. Speaker 2

    Will be 3 and like this.

  41. Speaker 1

    So you can write these two lines separately or you can write it like this.

  42. Speaker 2

    This is declaration and this is definition. Like we do with variables.

  43. Speaker 1

    I hope you understood this Now whenever we write this line So I told you what is happening in the backend through the compiler It will see the size of the array, it is the size of 3 arrays It means I have to allocate 3 memory Like this. 1, 2, 3. So, I have allocated 3 memories. Now, how many bits will each memory have?

  44. Speaker 2

    32 bits. Why?

  45. Speaker 1

    You think. Because I have this variable of integer type. It is written here and here. It is an integer type variable. And, Total I have to store 3 integers. So I have allocated 3 memory of 32 bits.

  46. Speaker 2

    In which? In my memory. Okay.

  47. Speaker 1

    Now what is the name of this whole memory? The name of this whole memory is roll numbers. So I have given it a name.

  48. Speaker 2

    Roll numbers.

  49. Speaker 1

    Something like this. So this is exactly the same. You think.

  50. Speaker 2

    Let's assume. I will tell you this. Remember.

  51. Speaker 1

    I used to write int x equal to 4. I used to write it in one place. So what does it mean? I have to allocate a memory container of 32 bits whose name will be x and its value.

  52. Speaker 2

    Will be 4. This is what it means.

  53. Speaker 1

    Similarly, when we write int let's say array equal to new int of size let's say 3. So I want to say here that I have to allocate a memory of 3 sizes and each memory will be of 30-32 bits and its name will be ARR So this is exactly the same, what I did here, I did that here. Here I just allocated one container of 32 bits, here I allocated three containers together, 32, 32, 32, okay? And named it ARR. Now remember, this memory will be allocated, it will be contiguous. Okay, what does contiguous mean? First is this container, after it, the second, after it, the third. It won't happen that one container is here, the second container is here, the third container is here in the memory.

  54. Speaker 2

    It won't happen like this.

  55. Speaker 1

    These three will be one after the other, their memory address will be one after the other. So, let's say its memory address is 1001, then it will have 1002 and 1003. Something like this. Obviously, after 1001, 2 will not come directly. Because after this, you will wait for 32 bits and then 1033 will come. Something like this. But you understood, the basic concept is that memory will always be contiguous. This is the concept of array. Now, how will we put value in it? We will see that later, how to allocate value in it. But I hope you understood the basics.

  56. Speaker 2

    What are arrays?

  57. Speaker 1

    What are arrays? They are collections of data types. We have written collections of data types here. After that, how do you declare an array? We have said that you declare and define it in this way. And what is its meaning? Its meaning is this, like the meaning of a variable. Now, let's go inside the arrays. Okay, very good. So, first of all, let's take this example with the same rule number. Let's say I have three students. I have one roll number, let's say 101. I have one roll number, I have 102. I have one roll number, I have 103. I don't want to represent this in different variables, I want to represent it in an array.

  58. Speaker 2

    So what will I do?

  59. Speaker 1

    I will write the same format int roll numbers equal to new int of size 3.

  60. Speaker 2

    Something like this.

  61. Speaker 1

    Let's write it a little correctly. new hint of size 3. This is how I write the first line. Do you know what will happen? I will have an array of 3 sizes. This is how it will be. Its name will be rollNumbers. Like this. Very good. Now let's see, we have declared an array. Now how do we add values to it? Suppose I want to add 101 in its first cell.

  62. Speaker 2

    How will I do it?

  63. Speaker 1

    I will write the syntax here. First of all, I will write the syntax. Role numbers, whatever the name of our array is. Our array's name is role numbers. I have to put the value on its zeroth index, 101. I will write something like this. Now, what did I say here? On zeroth index. First of all, I wrote the name of my array. Then, I opened my square brackets.

  64. Speaker 2

    Okay.

  65. Speaker 1

    Because you always represent an array with square brackets. Something like this. So, I opened square brackets. And I said, on zeroth index, I have to put the value 101. What is indexing? First of all, you have to understand this.

  66. Speaker 2

    Now, look. You have put an array.

  67. Speaker 1

    Means it has 3 containers of 32 bits and I also said this is a contiguous memory one after the other memory is allocated now how will I know which cell or which container I am talking about For that, whenever you declare an array, there are indexes in it. For example, its index is 0, its index is 1, its index is 2. Now, index is nothing. Index means you have to go to a particular cell. So, you will give a number of that cell. So, I gave its number 0, its number 1, its number 2. Now, Internally, in Java, the indexing of the array always starts with 0, not with 1. So, you call the first cell as 0, the second cell as 1, and the third cell as 2. So, if you ever want to put a value in the first cell, then you will write it like this. Roll numbers of 0. Roll number is the name of the array. In which index do you want to put the value?

  68. Speaker 2

    In 0th index. What do you want to put?

  69. Speaker 1

    101.

  70. Speaker 2

    As soon as you write this, what will happen? A value will be put here.

  71. Speaker 1

    101.

  72. Speaker 2

    Okay? Very good.

  73. Speaker 1

    Now if I want to add 102 in the second cell, then you must have understood that I will write roll numbers of 1 equal to 102. So here the value will be 102. And similarly, for the third cell, I will write roll numbers of 2.

  74. Speaker 2

    Equal to 103.

  75. Speaker 1

    So here the value will be 103. In this way, I filled all my values in the array. Very good. Okay, this value came here, this value came here, this value came here.

  76. Speaker 2

    Any problem with this?

  77. Speaker 1

    You must be able to understand how we have filled the values. Now we have filled the values. But now I have to retrieve the value. So how will I do that? Like it is the same thing that I have put x equal to 4. But I want to know what is stored in x. So what I used to do is system.out.println. I used to print x and I used to get the output on the fore screen. So I used to get to know from this. But now how can I print this?

  78. Speaker 2

    It's very simple.

  79. Speaker 1

    You must have got to know to a great extent on the same square bracket concept.

  80. Speaker 2

    I can write system.out.println.

  81. Speaker 1

    And suppose I want to print the first element So I will write the name of my array which is rollNumbers And I will write 0 in the bracket So my screen will be printed as 101 In the same way I can do rollNumbers 1 And my screen will be printed as 102 And in the same way I can do rollNumber 2 And my screen will be printed as 103 Something like this What can I do? Absolutely, I can do it. So, first of all, I declared the array. I also defined it like this. I also added the values in it and retrieved those values.

  82. Speaker 2

    Very good.

  83. Speaker 1

    But still, you are understanding a problem. Why did I make an array? So that I don't have to make a lot of variables one by one. I can make a container in one and store all the variables in it. But let me tell you one thing, I made a container of three lines from this line. So I didn't have to write it separately. But when I had to put a value in it, see how I was putting it. I was putting it one by one. Now let's assume that it is of only three sizes. But it would have been an array of 100 sizes. I could have put 100 elements in it. So, if I would have put them one by one, then I would have put row number 3, then 4, then.

  84. Speaker 2

    5, then 6.

  85. Speaker 1

    By doing this, I would have gone to 100. So, my manual work still increased. Same when I had to retrieve, I would have retrieved one by one. Manual work increased again. Now, remember here, what we can use, that we don't have to put the value one by one, but we start storing all these values together. Means, we use some block, and write some code in it, and fill all the values one by one. Remember, we read in the last lectures, loops.

  86. Speaker 2

    We can use loops.

  87. Speaker 1

    In fact, loops are used a lot to declare arrays, to define them, to retrieve values.

  88. Speaker 2

    Right?

  89. Speaker 1

    So, think about it. We don't have to write this. We can use loops too. We can run a for loop. First, from its 0th index to its last index.

  90. Speaker 2

    And we can fill values in all of them. Right? Let's see how.

  91. Speaker 1

    So, once we do this through loops, we declare a variable int rollNumbers equal to new int of size let's say 3. So, our 3 size array will be made.

  92. Speaker 2

    Let's make it right. It will be an array of 3 sizes. Like this. 0, 1, 2. Okay. What do I have to store in it? I have to store 101, 102 and 103.

  93. Speaker 1

    Okay.

  94. Speaker 2

    So, what did I do? I wrote a loop. What did I do first? I declared a variable. Let's say int. And I called that variable x for now. And I put 101 in it. Now I will tell you why I am doing this. Then look. I ran a loop for.

  95. Speaker 1

    Int i equal to 0 because we have to go from 0 index i less than 3 because less than 3 means it will go till 2.

  96. Speaker 2

    Because 3 will come out of the loop as soon as it happens. i plus plus.

  97. Speaker 1

    We have run a loop for loop. And see what I did inside. I wrote our array's name. Our array's name is roll numbers. Of ith index.

  98. Speaker 2

    Now see.

  99. Speaker 1

    First time ith index will be 0. Then it will be 1. Then it will be 2. 0, 1, 2. And every time I am putting on ith index. I am putting value of x. So first time it will be 1, 0, 1. Now I put value of x. Next time I want to put 1, 0, 2. So I will do x + + here.

  100. Speaker 2

    In loop.

  101. Speaker 1

    So I wrote this code. Look at this code carefully. First of all, you must have understood that I have run a loop from 0 to 2, basically 0, 1 and 2. Every time I put the value of x in the row number i and kept doing x plus plus. So the first time the value came was 101, the value of x was 101. After that, the value of x became 102, the next time it came 102, the value of x became 103, the next time it came 103. Now the value of x will be 104, but as it will go again, now the value of i was 0, 1, 2, now i will also be 3, i equal to 3 will be done, now i equal to 3 will fail here, so we will come out of the loop, right? That means I filled 101, 102, 103 inside the array, right?

  102. Speaker 2

    Using a loop.

  103. Speaker 1

    So I hope you understood how we can use loops to fill any values. Now think, if I want to print the entire array one by one, then also can't I use loops? Of course I can. I can make the same loop in the same way. For int i 0, i less than 3, i plus plus. I can open the loop in the same way. But this time I will do system.out.println. And what should I write? Whatever our roll number was, roll numbers of i. Keep printing roll numbers of i. So all three will be printed one by one. In the first line, it will print 101, 102, 103.

  104. Speaker 2

    Simple. Okay. So, you must have understood how we printed it through loops. Okay. Here I used loops to print.

  105. Speaker 1

    And here I used loops to declare the variable.

  106. Speaker 2

    Okay.

  107. Speaker 1

    So, now this manual work is removed. Which I was doing here. That I was declaring one by one. Then I was printing one by one. Now I don't need to do that.

  108. Speaker 2

    Okay.

  109. Speaker 1

    So, you must have understood this too. Now, think here.

  110. Speaker 2

    One more thing. I made an array of three sizes. Okay.

  111. Speaker 1

    So I wrote here I less than 3 If I made an array of 4 sizes So its index would be 0, 1, 2, 3 So I write here I less than 4 If it was of 100 Then I less than 100 I write like this Okay, but tell me one thing, should I make an array of any size? Do I need to hard code it here? Hard coding means that I should know the length of my array here. I will write the same number here. What if, where I am writing a loop in my code, I don't know the length of the array of this roll number? This can happen, right? You have a very big code base. There are multiple arrays in it. You don't know what its length is. What is the length of your row numbers array? And even if you know it, you don't want to hard code it here because its length can change tomorrow.

  112. Speaker 2

    So, I have to change its length by coming to this loop.

  113. Speaker 1

    Right? So, what do you do in that case? In that case, we get a special method. I will tell you what methods are there later. But for now, you think that our array, let's say we had an array of three sizes.

  114. Speaker 2

    Okay?

  115. Speaker 1

    This is 0th index, 1st index, 2nd index. The name of this array was our role numbers. And what were the values in it? You know, it was 101, 102 and 103. If I ever try to do this, system.out.println and what do I print?

  116. Speaker 2

    I write role numbers.length.

  117. Speaker 1

    If I write like this, Do you know what dot length will give us? Dot length will give us its size. It will print 3. Because there are 3 elements here. If there were 5 elements here, then it would give us 5. So dot length is an amazing thing. Whenever you write dot length in front of an array, first the name of the array and then the length, then we get the full size of the array.

  118. Speaker 2

    Now, we will study all these things like dot, length, etc.

  119. Speaker 1

    But now you should know that by writing roll number dot length, we get the size of the array.

  120. Speaker 2

    Very good.

  121. Speaker 1

    Now, I can take advantage of this in the loop. Now, if I want to loop, then I will start from i equal to 0. And I will go till i is smaller than roll number dot length.

  122. Speaker 2

    Something like this.

  123. Speaker 1

    Because roll number dot length is 3. What is its output? 3 will come. So, here I was writing 3 only. So, I directly wrote 3 and wrote roll numbers dot length. That whatever its length will be, whatever. It has to go till there. Now, whether its length is 3, 5 or 100.

  124. Speaker 2

    I don't know. And finally, you know that. After that, we will write I + +.

  125. Speaker 1

    And whatever we have to work here, we will work. Whether we have to allocate it, whether we have to print.

  126. Speaker 2

    It, etc. Okay.

  127. Speaker 1

    Very good. We understood this too.

  128. Speaker 2

    Okay.

  129. Speaker 1

    One last thing more. Now, as I made this array, this one, okay?

  130. Speaker 2

    So, what did I do?

  131. Speaker 1

    The array I made of roll numbers, it had 101, 102, and 103. And their indexing was 0, 1, and 2. And its name was roll numbers.

  132. Speaker 2

    If I tell you that.

  133. Speaker 1

    I don't want to loop in the entire array, I just want to print a particular element. So, you will say, no problem. Now, we can write this, system.out. println, okay which element do I have to print? Let's say I have to print 103, so I will write role numbers and which index do I want? 2, I will write 2 here, second index, so its output will be 103, because here 103 is stored, okay what happens, I will write system.out.println and I will write role numbers And write index 3 here which doesn't exist Or index 4 which doesn't exist If I write an index which is outside the limit of this array Then I will have an exception throw whose name will be IndexOutOfBoundException Now the first question that will come to your mind is what are exceptions? There are no exceptions. Java has a way of telling you that something is wrong. Now what is wrong here? The error is that the array's length was only of 3 sizes. In that, the indexing was 0, 1, and 2. You tried to fetch an element which is outside the limit of this array. So it said index out of bound. And if you put word with exception, then the total is index out of bound exception. So, exception means that Java compiler wants to tell you that there is something wrong in running this program. Now, exceptions will be made in depth in a different video. Later, it will be made that what are exceptions and what types are there. But now, if you see any exception on the screen, Any kind of exception, like index out of bound exceptions, there can be many more types of exceptions. But if you ever see an exception on the screen, you should understand that the compiler wants to give you a message that something is wrong. Something is wrong, you fix it. So whenever we try to fetch an element which is outside its index, we will get an exception, index out of bound exception.

  134. Speaker 2

    So whatever we have learned so far, let's.

  135. Speaker 1

    Quickly go to the screen, code it, and then come back and see what multi-dimensional arrays are. So again, we have made our project empty by doing demo.java and we have written our boilerplate code here. So first of all, we have to declare an array. So to declare an array, we are making this syntax. So role numbers equal to new int of size 3.

  136. Speaker 2

    Something like this. Right?

  137. Speaker 1

    So I gave the name of the array as rollNumbers.

  138. Speaker 2

    Let's call it rollNumbers. Something like this. Very good.

  139. Speaker 1

    Now, what did I tell you? If I want to put values in it, then one way is to put rollNumbers. First, I'll comment it and show you how our array is going to look. There are going to be three variables in our array. 101, 102, and let's say 103, something like this. So I can do one thing that I will put the roll numbers of 0th index in 101 and similarly I will put the roll numbers of 1st index in 102 and roll numbers of 2nd index in 103. 103, something like this. Okay, I have added the value. Now I can print it like this. What if I write system.out.println. println and how do I have to print it? roll numbers of, let's say 0th index. Sorry, 0th index. Something like this. And by doing this, I can print first as well as second. So first and second. Here I just have to change their indexing. First and our second. Now, if we run this once, then you can see 101, 102, 103.

  140. Speaker 2

    Very good. Okay, I'll print one more thing and show you.

  141. Speaker 1

    What we talked about, if I want to print the size of this area, then I'll write roll numbers dot l e n g t h length. Okay, let's print this and see. See, I also printed the length of this area, 3.

  142. Speaker 2

    Very good. Now, there was only one method. Right?

  143. Speaker 1

    And we talked about another method that we can use for loops. So, let's do one thing. First, let's do int x equal to 101. Which we saw earlier. So, for int i equal to 0. Because indexing starts from 0. How far will i less than go? What did we talk about? Roll numbers dot length. Because its value is the size of the array. So now it will be 3. And every time we will keep adding the array. And what we have to do is roll numbers of i-th index. So i-th index means first it will be 0. If the value of i is 0, then it will be 1. If the value of i is 1, then it will be 2. 0, 1 and 2 will run only 3 times. Because as soon as 3 happens, it will be equal to the roll number dot length. And here only less than operator is there. So it will come out of this loop. Okay, what value do we have to put? We have to put the value of x and every time we have to make x plus plus. Something like this. So I hope you have put the value by now. And then using the loop in the same way, we try to print the array. What does print mean?

  144. Speaker 2

    We can write system.out.println and here we write, let's say, roll numbers of i.

  145. Speaker 1

    Something like this. We printed the array. First, we defined a value here. We put all the values in the array. And we printed it here. So, let's see if we still get the same output. We got 101, 102, and 103.

  146. Speaker 2

    Okay.

  147. Speaker 1

    So, you must have understood how we declared the array. How we defined it. This is the way to make an array. Okay, let me tell you one more thing. It's not necessary that we put a square bracket in front of int.

  148. Speaker 2

    We can do it like this. Roll numbers.

  149. Speaker 1

    And we put a square bracket here. Let's say, these square brackets equal to new int. Three, this is also a correct declaration. You can declare it in this way and in this way as well. These square brackets can come after the row number or these square brackets can come after the integer.

  150. Speaker 2

    Why two ways?

  151. Speaker 1

    Let's assume that Java always prefers this way. But this way is also supported because it was supported in the old language. This is how you make an array in C, C + +. So to support a legacy, it has supported this method as well. So you can put this array sign in front of the roll number, which is square bracket. Or you can put it in front of the integer, which is the data type. And again, the rest of the things will remain the same. If you run it again, the output will be the same.

  152. Speaker 2

    It doesn't matter.

  153. Speaker 1

    Now, let's go back to the notes and see what are multi-dimensional arrays. So, now we have to see what are multi-dimensional arrays.

  154. Speaker 2

    What is multi-dimensional?

  155. Speaker 1

    So, first of all, let's go back to that array. We made an array int and we named it rollNumbers equal to new int of size 3.

  156. Speaker 2

    We declared the array in this way.

  157. Speaker 1

    And we said that whenever we write this, a contiguous memory will be allocated in our memory of 3 sizes, whose indexing will be 0, 1 or 2. And we would have added some value to it. So for now, let's assume that we have added some value to it.

  158. Speaker 2

    So this is how it works.

  159. Speaker 1

    This type of array is called in the language of computer science, one-dimensional array. One-dimensional array. Okay, what are the dimensions in this? The dimensions are that we are telling the computer that I want a contiguous memory. But in that contiguous memory, every element should be an integer. Right? We have written this here. We want a contiguous memory and every array's element should be an integer. Okay, now this is 1D array. So, what is 2D array?

  160. Speaker 2

    Okay? 2D array. In 2D array, you think what I am saying.

  161. Speaker 1

    I am saying that I can call this array of arrays. Like, what did I call 1D array? Let me write it here. I call 1D array array of any data type. Let's say int in this case. Here we made array of int. It was an array in which every value was an integer. Now think what I am saying here. I have an array in which every element is an array itself.

  162. Speaker 2

    This is called array of arrays. Interesting, right?

  163. Speaker 1

    So, let's see a little more about two-dimensional array. Again, what did I say?

  164. Speaker 2

    Array of arrays.

  165. Speaker 1

    So, first of all, I want to say that I will have an array. Let's say, it will be of three sizes for now. And in that, this element will not be an integer, but it will be an array in itself. This is what I call array of arrays. Now, this array itself, its element can be an integer. Same, its element can be an integer, its element can be an integer. In fact, all its elements will be integers. All of its and all of its. Basically, the one-dimensional.

  166. Speaker 2

    Array is this.

  167. Speaker 1

    And this represents our two-dimensional array. Because every element of it is an array itself. So, if you didn't understand the definition, it's okay. Now we will declare this array and show you. You will be able to understand more things. If you are wondering why we need a two-dimensional array, So the answer is for a lot of use cases. In fact, sometimes we need a 3D array, we'll see that later. But let's assume that you need multidimensional arrays. Okay, now let's go back to the starting and see how we declare this 2D array, how we define it, how we define it and how we store the value in it. But before going there Let's take an example of why we need a two dimensional array. For example, we have to store the student's roll number. We have stored roll number 1, roll number 2, roll number 3. And you know what are all the roll numbers?

  168. Speaker 2

    They are integers.

  169. Speaker 1

    So we have stored them in 101, 102 and 103 array.

  170. Speaker 2

    012, 101, 102, 103.

  171. Speaker 1

    We have done all this. Now we have to see Let's say I give you a scenario. Scenario is that I have 3 students. Student 1, student 2 and student 3. I have to store the marks of these 3 students.

  172. Speaker 2

    What do I have to store? Marks.

  173. Speaker 1

    Now the problem is that I don't have 1 mark of them. So it's not like I have 32 marks for this and 42 for that. It's not like that. They have different marks in different subjects. So if I explain it in the form of a table. So you understand that I have to store the marks of students.

  174. Speaker 2

    Okay. So I have to do it in this way.

  175. Speaker 1

    This student is S1, this student is S2, this student is S3. Now, let's say there are some marks in these three subjects. So, let's say this is your subject. I will write it in different colors. This is your subject, Hindi. This is, let's say, English. And this is, let's say, your computer science, CSC. So, I am saying, how many marks does student 1 have in Hindi? So, let's say his marks are, let's assume 50 for now. Let's say student 2 has 60 and student 3 has 70. Here, their marks will be 30, 40, 50 and 90, 80, 70. Their marks are like this. And I have to store this data in my memory.

  176. Speaker 2

    So now think.

  177. Speaker 1

    If I go in a traditional way, that I make a variable of everything, I don't know any arrays. So what will I do? First of all, I will make a variable int student1 hindi So, Hindi marks.

  178. Speaker 2

    Like this. Suppose I have named the variable student1 Hindi marks. 50. Then I will make student1 English marks.

  179. Speaker 1

    So, I will put 30. Then I will make student1 CSE marks. Do you understand?

  180. Speaker 2

    90.

  181. Speaker 1

    So, I need 3 variables to represent one student. Then 3 variables for the second student. Then 3 variables for the third student. So, to represent every student, I have to use 3, 3, 3 variables.

  182. Speaker 2

    Isn't it?

  183. Speaker 1

    Absolutely correct. So, if I don't have to do this, then I will try to make its array.

  184. Speaker 2

    Isn't it? But you think, can I make its one-dimensional array?

  185. Speaker 1

    Because look, I don't have directly one mark of student 1, I have three marks of it.

  186. Speaker 2

    So, if I make an array also, in which every.

  187. Speaker 1

    Column, represents a mark So I will have to put 3 marks here 1 mark won't work with 50 marks So if I am representing this for student 1 Then I will have to put 50, 30 and 90 marks Same, if I am representing student 2 in this I will have to put 60, 40 and 80 marks And so on for this one as well I will have to put 3 marks for this one as well So now think, how can I put 3 elements in one cell Which has every element as an integer.

  188. Speaker 2

    I can put it in the same way.

  189. Speaker 1

    Let me say that my cell is an array itself. It is an array of three sizes. And in that array, I am putting 50, 30 and 90. Sorry, here is 70, right? Yes, 90, sorry, it is 90. I am putting 50, 30 and 90. If I say this, then my work will be done. And from here, the concept of two-dimensional array arises. That such an array, if you look carefully, a lot of things. So, I say such an array, okay? where every element is an array and I have stored the marks or any integer in that array. So, in this case, 50, 30, 90. Similarly, this cell is an array and it has three values stored. What are those three values?

  190. Speaker 2

    60, 40, 80. Similarly, this is an array which has three values.

  191. Speaker 1

    Stores 70, 50 and your 70 so here 70 will come here 50 will come here 70 will come so okay I hope you understood what we want to say every cell is an array every cell is an array see I did one array here one array here one array here And in every array, I have added integer values. Something like this. So this is the concept of your two-dimensional array. And I have also told you how we use it. That if our data is multi-dimensional. Because we have two variables. One is student's marks. And marks are also in three subjects. Three students, three subjects. So I said let's make an array of array.

  192. Speaker 2

    Very good.

  193. Speaker 1

    Now let's see how to declare and define this Let's say we want to store this information, remember this table Remember this table, we will use this again and again That I want to store these marks in this array So let's see how to declare a multidimensional array I will write integer of Now if I make a one dimensional array, then I make one square bracket. Now because I have a 2D array, then I will make two square brackets. Something like this.

  194. Speaker 2

    Now I will name it as marks equal to new int.

  195. Speaker 1

    Now because I have made two brackets here, then I will make two brackets here as well. One bracket. 2 bracket and close. And obviously you know that we also write the size of the array.

  196. Speaker 2

    So let's mention the size here.

  197. Speaker 1

    So you know that I have to store the marks of 3 kids. And every kid's marks are in 3 subjects.

  198. Speaker 2

    So I made an array of 3 x 3. You can see that I have S1, S2, S3.

  199. Speaker 1

    To store the marks of 3 kids. And to store the marks of every kid in 3 subjects. Hindi, English, CSE. So I made an array of.

  200. Speaker 2

    3 x 3.

  201. Speaker 1

    Now we will see later how we can change this. Can I make this and this of different sizes? We will see everything. So I made an array of 3 x 3. Now think conceptually what I would have done. conceptually if we think about this diagram then how will our array look? I am thinking how will it look in memory so in memory our array will look like a matrix something like this I have made a matrix of 3x3 so let's say here I am representing the student and here I am representing their marks in the subject So my student S1, let's say this subject is Hindi, this subject is English and this subject is CSE. So student S1, S2, S3, this is Hindi, English, CSE. So S1' s marks here are 50, 30, 90. Let me write here 50, 30, 90.

  202. Speaker 2

    Similarly, 60, 40, 80.

  203. Speaker 1

    S2' s marks are 60, 40, 80. And S3' s marks are 70, 50, 70. 70, 50, 70. 70. So I assume that in the computer, something like this will be allocated to the memory.

  204. Speaker 2

    Think about it.

  205. Speaker 1

    One student will have marks of 1, 2, 3. Similarly, student 2 will have marks of Hindi, English and CSE. Then student 3 will have marks of Hindi, English and CSE. In this way, some marking will be done in the computer. Now I will tell you how it works in reality. Conceptually, when we try to visualize a two-dimensional array on our screen, we will do it in the form of a matrix. And we can write here that the size of our array is 3x3. 3x3 means it has 3 rows. See, row 1, row 2, row 3. We call them rows.

  206. Speaker 2

    R1, R2, R3. And there are 3 columns. C1, C2, C3.

  207. Speaker 1

    Column 1, column 2, column 3. We call them columns. So, the horizontal lines are our rows. The vertical lines are our columns.

  208. Speaker 2

    Okay? So, this way I can represent my array. Okay?

  209. Speaker 1

    So, if you think, I will remove this. You must have understood that these are rows and columns. If you think that I write the names of these columns and rows. It means that let's suppose I draw it again. I have drawn it like this. 3 cross 3.

  210. Speaker 2

    Okay. So now think.

  211. Speaker 1

    This is my R1, Rho1, this is my Rho2, this is my Rho3. This is my column 1, this is my column 2, this is my column 3. This cell of mine, what is it representing? Rho1, column 1. This cell represents row1, column2. So if I do indexing of this. So let's say I do indexing like this. Column1 is 0, 1, 2. Similarly here also 0, 1 and 2. Let's write it a little clearly. So for now I say this is my 0, this is my 1th index, this is my 2nd index, same, this is my 0 index, this is my 1 index, this is my 2nd index, so I can do its indexing in this way, like I did my 1 dimensional array indexing, how did I do it? I declared an array like this, I said this is 0, this is 1, this is 2, now here I have 2, 2 dimensions, so I did indexing.

  212. Speaker 2

    Here as well, so I can say that this one, my.

  213. Speaker 1

    Sorry, it's a cell. I can represent it from 0,0. From 0,0.

  214. Speaker 2

    Right? Similarly, from 0,1. From 0,1. And from 0,2. Similarly, our 1,0. 1,1. 1,2.

  215. Speaker 1

    Similarly, our 2,0. 2,1. 2,2. Can't I declare it like this?

  216. Speaker 2

    Right? I can definitely do it. Okay? Now, first I took the name of row, then column. Row, column. Row, column. Row, column.

  217. Speaker 1

    And in the same way, when I defined the array here, the first three I wrote, this represents my rows. And the second three I wrote, this represents my number of columns.

  218. Speaker 2

    So, you have to remember. Okay?

  219. Speaker 1

    That's why I showed you by drawing the whole thing. So that you understand what the first three tells and what the second three tells.

  220. Speaker 2

    So, let's write it too.

  221. Speaker 1

    This is representing the number of rows. And this is representing the number of columns. Now, you understood. So, my number of rows is 3. See, there are 3 rows.

  222. Speaker 2

    R1, R2, R3. And I have 3 columns. C1, C2, C3.

  223. Speaker 1

    There are 3 marks here. So, you can see this too. And you can see this too. This is its conceptual view. That how my rows and columns are arranged. If you understand these two things, how I defined it and how conceptually I am imagining that our array will be stored, then I can store the values in this array and I can also retrieve.

  224. Speaker 2

    The value, that is, I can also print it.

  225. Speaker 1

    So, just now I had written this line on the screen, int marks equal to new int 3 comma 3, that is, I was assuming that my 3 comma 3 name, of such a name, The matrix will be ready in memory. It will have 3 rows R1, R2, R3 and 3 columns C1, C2, C3. And every cell will have a number like 0,0.

  226. Speaker 2

    Why?

  227. Speaker 1

    Because it has 0th row and 0th column. Let's erase it from here. Similarly, what will be the column of this cell? 0,1 because it has 0th row and 1st column. And 0th, 2 because it has 0th row and 2nd column. You must have understood that after writing this line, what did I imagine? I imagined that in the computer, this would have been done. This much work would have been done. Now I have to fill values in it. I have to fill these values. So how will I fill? Okay, let's think. First let's remove this. And let's see this again.

  228. Speaker 2

    This one. Let's see this again. I want to fill these values 50, 30, 90, 60, 40, 80, 70, 50, 70.

  229. Speaker 1

    Let's assume that the values are not filled. So I will remove its values. So let's say I removed 50, 60, 70, 50, 40. I removed these values. I want to fill the values in this.

  230. Speaker 2

    Okay.

  231. Speaker 1

    How can I fill it? You remember, we saw that we can go through loops. And one by one, in all three, basically in arrays, we can fill values.

  232. Speaker 2

    Right? We saw this. Okay.

  233. Speaker 1

    Now, how will we fill a value in a two-dimensional array using loops? If we run a single loop, you know, if we run a single loop, for i equal to 0 to i less than 3, i plus plus, if we run a loop like this, then it would have filled a row, right? Then we would have to run another loop to fill a second row, we would have to run another loop to fill a third row, right?

  234. Speaker 2

    Do you understand? Right?

  235. Speaker 1

    What would this loop do? It would fill a row. Let's say I write array of equal to a value. So I put it in this, then in this.

  236. Speaker 2

    Then in this.

  237. Speaker 1

    But I want it to have value in this as well as in this. What do I have to do to do that? I have to use nested loop. In one loop, in the other loop.

  238. Speaker 2

    I have to use nested loop in this way. Right?

  239. Speaker 1

    Absolutely correct. Okay, now the problem is that even after using the nested loop, every value is different here, right? Every value is different here. So there is no pattern in it that I can say directly that fill 101 in this, then 102 in this, then 103 in this, 104 in this, 105 in this.

  240. Speaker 2

    There is no such pattern.

  241. Speaker 1

    Like I had made in my one-dimensional array that keep filling the roll number by doing next next. If you don't remember, then you can see something like this.

  242. Speaker 2

    Right?

  243. Speaker 1

    First one is 101, second one is 102, third one is 103. So what did I do for that? I declared a variable x equal to 101 and kept doing x + + every time. But here we can't do anything because all the numbers are different. So obviously, we will have to fill them individually. We will have to fill them individually. So let's see how to fill them individually. Let's say for now, I will write the value again.

  244. Speaker 2

    50, 30, 90.

  245. Speaker 1

    I shouldn't have erased this. I am remembering now. 60, 40, 80. 60, 40, 80.

  246. Speaker 2

    And 70, 50, 70.

  247. Speaker 1

    Let's say I filled this value in some way. Now how did I fill it in some way? I'll tell you one by one.

  248. Speaker 2

    I must have written, my array name is marks. Okay, look at this. My array name is marks. Okay, so I must have written. Let's keep it like this.

  249. Speaker 1

    So, my array name is marks, I have written, in my marks array, which value I have to fill first? First, I have to fill this value, which means row 1, column 1. So, I will write, in 0th row, because you know, our first row tells, in 0th column, second column tells, here I have written, first row tells, The first row tells, the second column tells. So I wrote in my 0th row, in the 0th column, I have to fill a value which is 50. So we must have understood. 0th row, 50 in the 0th column. So I can fill the value in this way. Now suppose I have to fill the 0th row in the first column. That is, 0th row, this row and first column. I have to put 30 in this. So how can I write again? I can write again marks 0th row 1st column equal to 30. Here 30 came. Similarly marks 0th row 2nd column equal to 90.

  250. Speaker 2

    Here 90 came. I can write like this. Now think if I want to put 60 in 1st row and 0th column.

  251. Speaker 1

    So I will write marks First row, means I am talking about this row. 0th column, means I am talking about this column. I have to put value of 60 in it. So, I can write like this. Now, you must have understood how I will keep writing the rest of the values. I just need to remember row number and column number.

  252. Speaker 2

    Right?

  253. Speaker 1

    So, if I just get row number and column number, then I can keep adding value to them.

  254. Speaker 2

    Very good. So, I have added values here. Okay?

  255. Speaker 1

    I have added values here. Now, if I want to retrieve them, how can I do it? I can do it using nested loops, which we saw earlier. By using nested loops, what does nested loop basically mean? By using one inside another loop, I can print this entire matrix.

  256. Speaker 2

    So, let's try it.

  257. Speaker 1

    First of all, let's copy this matrix down. So, what I did was, I simply printed it down again, the matrix that we had made. Now I have to print this matrix and I need 2 loops which we call as nested loops. So what I can do is that I will go like this that first I will print row 1 basically 50, 30 and 90 then I will print row 2 60, 40, 80 and then I will print row 3 70, 50, 70.

  258. Speaker 2

    Something like this.

  259. Speaker 1

    So, the first outer loop will travel in this row. And the inner loop will print these columns in each row.

  260. Speaker 2

    Remember?

  261. Speaker 1

    If you have practiced patterns in loops, then you must have understood how to do this. So, let's say, first of all, I write outer for loop for int, let's say, row. int row equal to 0. How far will row go? Less than 3. row plus plus. Something like this. Our row will start from 0 and go till 3. So this is our outer loop. Now what can I do after this?

  262. Speaker 2

    I'll write an inner loop. Let's say for int column.

  263. Speaker 1

    Let's write col. Column will also go from 0. Column can also go till 3. And column plus plus. Something like this. So basically, my column can also go from 0 to 3.

  264. Speaker 2

    Okay. Very good.

  265. Speaker 1

    And every time, what am I doing? First, let's close this. This too and this too. Every time, I system dot out dot print ln. I mean, I don't write print ln. I just write print. So that we can print in one line. We are trying to print.

  266. Speaker 2

    What? Our array's name is marks. Which row is its? Row at row.

  267. Speaker 1

    And sorry, row with row and col, column with column we are trying to print this ok, so what will happen in this first of all, our flow of control It will come in this loop, it will define row as 0, then it will come in the inner loop and define column as 0 And it will print marks as 0,0 which means it will print as 50 Then this loop will run again, then it will say that row is still 0 and I have done the value of column as 1 So it will print 0,1, now 0,1 is 30, so it has printed 30 Then this loop will run again, row is still 0 and column value is 2. So it will print 0,2 which is 90. Once one row is finished, this loop is finished. Now outer loop will run again and row value will be 1. Now this will work for one row. So 1, 0, 60, then 40, then 80. It will print like this. Then again this inner loop will end. Then again outer loop will run. This time the value of row will be 2. Now we will print the values of second row. We will print 70, 50, and 70. And this way our work will continue. Again, as we used to do in pattern printing. Once this loop ends, we will have to put a new line. So we can write here system.out.print. So that we can add a new line. To print each row, like we printed one row 50, 30, 90. After that, we change our line and come here. So that we print 60, 40, 80. Then we change the line and come here. We can do something like this.

  268. Speaker 2

    Okay.

  269. Speaker 1

    This way, you think, you will print your entire two-dimensional array.

  270. Speaker 2

    You will do it, right? Okay, very good.

  271. Speaker 1

    So, we saw how we can make a two-dimensional array, how we can conceptualize it, and how we can print it after visualizing it.

  272. Speaker 2

    Very good.

  273. Speaker 1

    Now, obviously, if the values are different, then you will have to put the values manually.

  274. Speaker 2

    Okay.

  275. Speaker 1

    The first square bracket represents rows, the second square bracket represents columns. So, you must have got the idea by now.

  276. Speaker 2

    Okay.

  277. Speaker 1

    If you understood these things, then I have to go one step further. And I want to tell you that till now we were talking about conceptual representation.

  278. Speaker 2

    What were we talking about? Conceptual representation. Representation of 2D array. Okay.

  279. Speaker 1

    Basically I told you that conceptually 2D array are represented like this.

  280. Speaker 2

    How? In this form. In the form of a matrix.

  281. Speaker 1

    But logically, when you look at it in memory, it won't be represented like this. Let me tell you how it will be represented. Think about what memory will do. Whenever you write, marks, or let's start with this. Let's say I write int, I made a 2D array, marks, and write it equal to new int, Rows and columns.

  282. Speaker 2

    Let's say 3 rows and 3 columns. Something like this.

  283. Speaker 1

    As soon as I make it, my compiler will go to the memory and tell me the size of the array to be made. Remember, for compilers, no row and column concept exists. This is for our visualization. Because humans like to represent everything in a pictorial form. Because our brain works like this. Our mind will look at this. And like we read matrix in Maths, we look at matrix and say that.

  284. Speaker 2

    This is a two-dimensional thing.

  285. Speaker 1

    It has some rows, it has some columns. Our mind thinks like this. So whenever we represent a data in the form of a matrix, we do it this way, by making tables. So remember, when we read SQL, query languages, we imagine data in the form of tables and rows. But actually data is not stored. In the same way, data will not be stored in the computer. Computer has neither a concept of rows nor a concept of columns. It has a concept of contiguous memory location. Remember, I am explaining this a little internally. Memory location So how will you store it from the computer? The computer will directly think in its memory That I have to make an array of marks And its size is 3 So basically what I have to do is I have to make 3 containers Very good Okay, I will make this But what type of container will my every container be? Will it be of integer type? No My every container Is itself an array Do you remember what I said in the beginning? My every container is also an array This one and this one. So what I have to do is, first of all, I have made an array of three sizes and every element of it is storing another array. So let's say this one is also storing an array. Its size is also 3. 1, 2, 3. This one is also storing an array. Its size is also 3. 1, 2, 3. And this one is also storing an array. Its size is also 3. 1, 2, 3. The memory will be allocated in this way in the computer.

  286. Speaker 2

    Okay, let's explain this again. You will understand it better.

  287. Speaker 1

    Let's say, the computer will first make an array of three sizes. Because it knows that it has to make three containers. And what should be the size of each container? I will tell you that when we have read references and objects. Because these arrays will make an array of objects. But don't go so deep into what objects are. Just understand that as soon as the computer makes an array of three sizes.

  288. Speaker 2

    Why?

  289. Speaker 1

    Because we have told it that we need an array of three sizes. Now, when I write the next three, I will tell it that every array, sorry, every container, this container, it is storing an array itself. So, let's say it will say, oh, so I basically have to put one more new array in this container. And similarly, I have to put one more new array in this container. And similarly, I have to put one more new array in this container. Something like this it will think.

  290. Speaker 2

    Okay.

  291. Speaker 1

    And then when you write like this, when you write, marks, 0 comma 0 equal to let's say 23. Here what value did you fill?

  292. Speaker 2

    50.

  293. Speaker 1

    Here this value was 50. So let's say if you write marks 0 comma 0 equal to 50. So it will not think in rows and columns. It will think that first of all what did you write? First of all you wrote first 0.

  294. Speaker 2

    Means I want 0th.

  295. Speaker 1

    This first container of marks is called marks. So the first container of marks, I have to go to its 0th index. This is 0, this is 1, this is 2. Let's write indexing here. This is 0, this is 1, this is 2. I have to go to 0th index. Now, as soon as I reached this index, it is representing an array itself. And in this new array, the indexing will be.

  296. Speaker 2

    0, 1, 2. In this too, 0, 1, 2. And in this too, 0, 1, 2.

  297. Speaker 1

    Where do I have to go in this new array? I have to go to the 0th index. So, I have to go to the 0th index of this too. And I have to store a value of 50 in this.

  298. Speaker 2

    So, it will store like this.

  299. Speaker 1

    Then, when you write marks 0, 1 equal to, let's say, what have you written? 0, 1 equal to 30. So, you write 30. So, what will it do? First, this one, It will go to the 0th index of this array. It will say that I am standing here. And it is representing an array itself. And it will go to the 1st index. Meaning here. And it will put a value here.

  300. Speaker 2

    30. So it stored 30 here.

  301. Speaker 1

    And it starts filling the value in this way. And this happens exactly in memory.

  302. Speaker 2

    Okay. This is not conceptual representation. This is. Sorry.

  303. Speaker 1

    We had seen conceptual till now. I should say this.

  304. Speaker 2

    Logical.

  305. Speaker 1

    Logical representation of 2D arrays. That how we represent 2D arrays inside the computer.

  306. Speaker 2

    Okay. So I hope you understood this. If you understood this.

  307. Speaker 1

    Then you will understand the depth of the array. How things are stored. Things are not stored in rows and columns. Like this. Computer doesn't work in tables. Computer works like this. So we have to do contiguous memory allocation. And we have to tell it that every element. itself is an array, so it has pointed it towards a new array. Now this array has been pointed towards this array. This array has been pointed towards this array.

  308. Speaker 2

    Okay?

  309. Speaker 1

    So when we fill values like 0,0,0,1,0,2, then it fills in this way that first it goes to this index, then to its first index, second index, or the 0th index. Like this.

  310. Speaker 2

    Okay? Very good. You understood this too. Okay, now another thing.

  311. Speaker 1

    When I wrote here that row will go to 3 and column will also go to 3, even then I had hardcoded it, right? Like I wrote in one-dimensional array, whatever the name of my array was, there were roll numbers, so I wrote roll numbers dot length, something like this.

  312. Speaker 2

    Can't I do the same thing here? Absolutely I can.

  313. Speaker 1

    But to explain that, first I had to explain to you that how exactly things are stored in the computer. Because if you understand this, then you will understand how I will write those loops with dot length. So now imagine this data again. And suppose I have to write our loop in this way. So I will do one thing, I will copy this again. So what I did is, I copied this loop again, that how I printed row less than 3, column less than 3.

  314. Speaker 2

    And what was the data we had?

  315. Speaker 1

    This was the data. Let's copy this once. So I copied this too. We ran this loop and we tried to print this data. 50, 30, 90, this way and this way. Now I am saying that instead of row less than 3 and column less than 3, I have to write something else. I have to write in the same form that dot length is dot length. So how can I write? Now I have definitely explained this to you. If you understand this, then you will understand what will come here and what will come here. According to the computer, it has an array whose name is marks. I will write it here. The name of this array is marks according to the computer. And the length of the marks is 3. 0, 1, and 2.

  316. Speaker 2

    Remember.

  317. Speaker 1

    Every element of the marks, like this element, is an array itself. And the length of all of them is 3. 3, 3.

  318. Speaker 2

    Okay.

  319. Speaker 1

    So, if its name is marks, the name of this big array is marks, then the 0th index of marks, One second, let me tell you. If the name of this big array is marks, then this index of marks would be called marks of 0.

  320. Speaker 2

    Right?

  321. Speaker 1

    Similarly, if the name of this whole array is marks, then this middle index.

  322. Speaker 2

    Of marks would be called marks of 1. Right?

  323. Speaker 1

    We were doing this till now. And again, if the name of this whole array is marks, then the name of this second index of marks would.

  324. Speaker 2

    Be marks of 2. Right?

  325. Speaker 1

    Okay, I am saying that the compiler will understand that marks of 0, means this one, is an array itself. So marks of 0 is an array itself. And what is its size? Its size is also 3. So if I write marks of 0 dot length, then our 3 will be printed.

  326. Speaker 2

    Understood?

  327. Speaker 1

    So what I mean to say is, if I write marks of 0 dot length on the screen, then our 3 should be printed. Similarly, if I write marks of 1.length then also our 3 should be printed because marks of 1 is this itself is an array and if I will put dot length operator on it then it will also give me the size of that array and in fact I can simply put dot length on marks too marks dot sorry I can simply write marks dot length I can write it like this also. Because marks is also an array. So I can write dot length on the name of this marks. I can write dot length on the name of marks 0. I can write dot length on the name of marks 1. And dot length on the name of marks 2.

  328. Speaker 2

    Right.

  329. Speaker 1

    So I hope you understood this. So if you understood this. Then it is exactly the same. What I will write here. First of all. This is our outer loop. This is our outer loop. Instead of this I will write 4. int row equal to 0 and row less than marks dot length marks dot length row plus plus so I will write this in outer loop ok marks dot length means I am saying that I have to run this loop till its length till its length till the length of this big array first thing ok very good then in the inner loop in the next loop I will go for int Column equal to 0.

  330. Speaker 2

    Column less than. These marks. Marks.

  331. Speaker 1

    On its row, now marks of row, means basically, first time I am talking about marks of 0, next time marks of 1 and next time marks of 2. So, first time this row's value will be 0, so I will talk about marks of 0. Next time this row's value will be 1, so I will talk about marks of 1. And next time row's value will be 2, next time means when this outer loop will run again.

  332. Speaker 2

    So, I will talk about marks of 2.

  333. Speaker 1

    I am saying that every time I have to go to marks of row dot length and column plus plus. Something like this. And I will print the same inside here. But I just told you that instead of row less than 3 and column less than 3, I wrote row less than marks dot length, column less than marks of row dot length.

  334. Speaker 2

    Marks of row dot length. You have to keep this in mind.

  335. Speaker 1

    Because our computer is storing this data from inside. Something like this. It is saying that I have only one array of marks. Every element has its own array. So I can add dot length on this too. And I can add dot length on this as well. I can add dot length on the first array as well. And I can add dot length on the second array as well. I can use dot length operator to loop in my entire matrix. So remember that this is just a conceptual overview which we imagine how it will be stored. And this is a logical overview. So actually the way data is stored in the computer.

  336. Speaker 2

    Right? I hope you understood this thing.

  337. Speaker 1

    If you understood this conceptually then you understood everything. But still you need to understand this. That why we are putting marks dot length here. And why we are putting marks of row dot length in the inner loop. It is important to understand this. Otherwise, you will imagine that this is also going to 3 and this is also going to 3. So, I can write something like this. Marks.length and inside also marks.length. You will do like this. Yes, it will work for this because marks.length's value is 3. And here if you write marks.length then also it will work but it will be wrong when every row is of a different length and yes you can do this too we will see how we can do this but I hope you understood how you represent a two dimensional array if you understood this whole story then we will move a little further and see one more concept Let's say this was our two-dimensional array. Which array?

  338. Speaker 2

    This one. 50, 30, 90, 60, 40, 80 and 70, 80, 70. This array. So how did we represent it?

  339. Speaker 1

    We said int two-dimensional array marks equal to new int and we gave here rows and columns. I am saying that giving both these values together is optional. If you want, then you can give only one value which is row. Giving row is compulsory. Meaning, this number of rows, what is this? This is compulsory. Meaning, while defining any array, you will have to tell that how many rows are there in it.

  340. Speaker 2

    But for now, this is optional. You can give it later also. What does it mean?

  341. Speaker 1

    So, you are saying to the computer, to the compiler, that I want We need an array of 3 size. We need 3 containers in an array which will have indexing of 0, 1 and 2.

  342. Speaker 2

    But you haven't told.

  343. Speaker 1

    The computer that every element of it, like this is the 0th element, this is the 1st element and this is the 2nd element. This itself is an array because you gave it 2 brackets and it understood that this 0th index is also an array.

  344. Speaker 2

    But what is the size of this array? You haven't told it yet. No problem, tell me later.

  345. Speaker 1

    By the way, you are saying that the first one is also an array, but I am not telling its size yet. Similarly, the second one is also an array, but I am not telling its size yet.

  346. Speaker 2

    I will tell you later. You want to say this. Okay. No problem, you can do this. You can do this. Okay.

  347. Speaker 1

    But now I was saying, if I have to declare it later, how will I do it? I can do it like this. First, let's do one thing.

  348. Speaker 2

    Let's remove this. You must have understood. This row is optional. Now I can do this. I will write marks sorry marks.

  349. Speaker 1

    Of zero marks of zero means you are telling the compiler that you must have made a big array of three size whose every value is an array itself this is index 0, index 1 and index 2 so I am talking about this zero one that what is the size of this array itself so you can tell its size separately marks of zero equal to new again new operator Int of size, let's say 2.

  350. Speaker 2

    So, you are saying marks of 0 is just an array of 2 size. Okay.

  351. Speaker 1

    Similarly, you can tell again, let's say marks of 1.

  352. Speaker 2

    Means, this array. This one. Which will have an array in itself.

  353. Speaker 1

    Right.

  354. Speaker 2

    Which will have an array in itself. What is its length?

  355. Speaker 1

    So, you can say new int of size, let's say 3. So, its size is 3. So, you are seeing, I am declaring different sizes here. Let's make it a little lower. So now comes the next value, so I can write marks of 2. Means the second index which is an array itself, what is its length? So let's say I make it length 3 or 4, new int 4.

  356. Speaker 2

    I.e.

  357. Speaker 1

    Its length is 4, i.e. it can store 4 elements. So basically, what did I do? I declared all the elements in different ways.

  358. Speaker 2

    So first, I made a marks-carrier, new int of size 3.

  359. Speaker 1

    And now the column doesn't tell anything because all the columns are different. So first of all, the compiler made a container of 3 sizes. Then I said, the marks of 0, i.e. this one, This itself is an array whose length is 2, so this itself is an array whose length is 2.

  360. Speaker 2

    Marks of 1, means this one. This itself is an array whose length is 3, so this itself is an array whose length is 3. And similarly, marks of 2, means this one.

  361. Speaker 1

    This itself is an array whose length is 4, so this itself is an array whose length is 4.

  362. Speaker 2

    Okay? So, I have told the computer something like this.

  363. Speaker 1

    Now look, this is a logical overview of how to store from a computer. But how will we imagine this? We will imagine a matrix whose length is different for all the columns.

  364. Speaker 2

    So what did I say? I will imagine like this.

  365. Speaker 1

    How I had imagined it earlier, I had imagined it 3 by 3, 3 rows, 3 columns, so row 1, row 2, row 3, similarly here column 1, column 2, column 3, earlier I had imagined it like this, but now the data is not like this, so see, I have rows here still 3, see, marks 0, marks 1, marks 2, because you know the earlier one tells rows, this 3 tells me rows, So I have to represent 3 rows in this way.

  366. Speaker 2

    Row1, row2, row3. row1, row2, row3.

  367. Speaker 1

    So there are 3 rows. But the number of columns are varying. So in the first case I have 2 columns. So I have 1 column here and 1 column there. Let's make it with a pen. 1 column here and 1 column there.

  368. Speaker 2

    C1, C2. Like this.

  369. Speaker 1

    Next time there are 3 columns. So column 1 is this. Column 2 is this. Column 3 is this.

  370. Speaker 2

    This is your C3. Right? And next time there are 4 columns.

  371. Speaker 1

    So column 1, column 2, column 3 and column 4.

  372. Speaker 2

    Something like this. And this is my C4. This one. This C3.

  373. Speaker 1

    Okay? So I will represent the matrix in this way. Something like this.

  374. Speaker 2

    Okay?

  375. Speaker 1

    I hope you can understand why I have done different representations like this Because in the first row, I have C1, C2 In the second row, I have C1, C2, C3 In the third row, I have C1, C2, C3 and C4 If I write their indexing again This is my 0, this is my 1, this is my 2 This is my 0, this is my 1, this is my 2, this is my 3 So I will write 0, 0, 0, 1 0, 0, sorry 1, 0, 1, 1, 1, 2. Similarly, I will write 2, 0, 2, 1, 2, 2, and 2, 3. Something like this.

  376. Speaker 2

    Right?

  377. Speaker 1

    So, I hope you have understood that I can make an array in different lengths. Basically, a two-dimensional array is such that each row is.

  378. Speaker 2

    Of different length. I can also do this.

  379. Speaker 1

    How can you believe that I have multiple students and each student has different subjects. Some have 3 subjects, some have 4 subjects. So, the one who has 3 subjects, he will have 3 marks. The one who has 4 subjects, he will have 4 marks. The one who has 2 subjects, he will have 2 marks. So, I have different students, but each student's marks... The number of subjects are different. So, the number of marks are also different. Right? So, for that case, I need a matrix whose length of every column is different.

  380. Speaker 2

    Right?

  381. Speaker 1

    So, I can do this using my this method. So, I hope you understood this too. So, one last thing. Like I told you about one-dimensional array. If this line is correct, then I can write the alternative of this line like this.

  382. Speaker 2

    First, I write int marks.

  383. Speaker 1

    And put two brackets in front of it, equal to, everything else is the same, new int, Something like this.

  384. Speaker 2

    I wrote 3 here. Okay? So I can also do this.

  385. Speaker 1

    It means I can add square brackets with int and square brackets with marks.

  386. Speaker 2

    It doesn't matter. Both are identical.

  387. Speaker 1

    But you just had to understand that I can make a two-dimensional array of different lengths. This is my conceptual representation. I am thinking. This is how it is represented. But what is the physical representation? I told you that too. Where did I tell you?

  388. Speaker 2

    Here.

  389. Speaker 1

    This is my physical representation. or logical representation that how the computer is storing it from inside. It is not storing in this form. So it is storing in such a way that it makes a big array which has three containers. And every container itself is an array. And the sizes of every container are also different.

  390. Speaker 2

    Okay? Okay.

  391. Speaker 1

    So I hope you understood what we did. We saw the conceptual overview as well as the logical overview.

  392. Speaker 2

    That how things.

  393. Speaker 1

    Will be stored from inside and how we imagine it. In this way, we imagine that things will be stored. And I had told you the conceptual overview above. Where did I tell you?

  394. Speaker 2

    Here.

  395. Speaker 1

    What will happen in conceptual? That we will imagine that we have a marks. Whose every element is an array itself. And it can be of different size. So in this case, what I told you? That first of all compiler will make a array of marks.

  396. Speaker 2

    This is 0 index, this is 1 index, this is 2 index. And we will call it as marks. Okay.

  397. Speaker 1

    And every index itself has an array. Whose size is different. The size of the first one is 2. The size of the second one is 3. And the size of the third one is 4. So I make it in 4. Something like this. So I will call this as marks0, marks1, and marks2. These are the names of the arrays. This is its actual representation which the computer does in memory. So if I call this as marks0, then I will have to call this index as marks0. So I will call this index as marks0 array. its zero index, means this one. Okay, if I have to say this, then I will say, marks two is the name of the array, and its first index. So, marks two and its first index. So, this one is there, because this is zero and this is one. Okay, so if you have understood all this, then you have understood the concept of all the arrays very well. After this, one last thing remains, that, okay, you imagine, like this, if I say, what a 3rd dimensional array is. Multidimensional means, it can be of any dimension. Now, what does third dimensional mean? I will have an array declaration of this kind. int, 1 bracket, 2 bracket, 3 bracket. And let's say, I can say anything. For now, I will just call it array. Equal to new int. Now, three things will come in this.

  398. Speaker 2

    Three things. Okay.

  399. Speaker 1

    So, let's say I make a three-dimensional array of 3x3x3.

  400. Speaker 2

    Okay.

  401. Speaker 1

    So, this means, if I talk about logical representation, the computer would think that I have to make an array of.

  402. Speaker 2

    Three sizes.

  403. Speaker 1

    So, it made an array of three sizes. Its name is ARR. Now, the computer understands that That the array of 3 sizes that I have made Each element of this is an array itself Because I have put it in the second square bracket So it will understand that this itself is an array This itself is also an array And this itself is also an array How many size arrays are these? These are also 3 size arrays because I have already defined it as 3 So it also made an array of 3 sizes.

  404. Speaker 2

    Very good.

  405. Speaker 1

    Then it thinks that if this is arr.

  406. Speaker 2

    And its indexing.

  407. Speaker 1

    Is 0, 1 and 2, then what is the name of the first one? I told you that its name is arr of 0. Its name is arr of 1 and its name is arr of 2.

  408. Speaker 2

    Absolutely correct.

  409. Speaker 1

    Let's write the indexing of this as 0, 1, 2. 0, 1, 2. 1 and 2 and it also has 0, this is 1 and this is 2 I have written indexing in this way Then it will again go to this element And it will say that the list of my second arrays A, R, R0, A, R, R1 and A, R, R2 Each of its elements is an array itself So this is also an array, so it means again you must have understood This is also an array And again it is of 3 sizes, in that this is also an array Again, it is of 3 sizes. And this is also an array. Again, it is of 3 sizes.

  410. Speaker 2

    Okay. Now, you have reached this level. Okay.

  411. Speaker 1

    What will be the name of this level? Obviously, it will be ARR of 0, 0.

  412. Speaker 2

    Okay. This is ARR. This is ARR of 0. And this is the 0th element of ARR 0. So, ARR 0, 0. Now, you have reached this level. Okay.

  413. Speaker 1

    Now, your compiler is saying that every element of this All these elements have an integer value which means that it will store an integer value. So I can store values like 3, 4, 7, 2, 5, 8 in this way. So first I came down one level, then I came down the second level and stored the integers inside them. Similarly, I will do the same here. All these will also have an array. This is called a three-dimensional array. So, one array whose every element is a single array. Now, again, this is the logical representation of how a computer thinks. If you want to make it conceptual, then assume this is a 3D world. So, what will you do? You will make a matrix. Something like this. This is a row. Row 1, row 2, row 3. This is column 1, column 2, column 3.

  414. Speaker 2

    Okay?

  415. Speaker 1

    And you will assume that it will have multiple dimensions. This is a 2D matrix. Now, there will be multiple 3D combinations of this 2D. You assume that you have a square.

  416. Speaker 2

    Okay? This is a 2D thing.

  417. Speaker 1

    Okay?

  418. Speaker 2

    But you have a cube. Cube. It's a 3D thing.

  419. Speaker 1

    And how does a cube form? This multiple squares layer, keep stacking it on top of each other.

  420. Speaker 2

    Like this. So, you won't form a cube. Some third dimensional. Right?

  421. Speaker 1

    What I did was, I started stacking multiple squares layers on top of each other.

  422. Speaker 2

    Something like this. And this became our cube. Right? Similarly, you took a 2D matrix. Okay?

  423. Speaker 1

    And you started stacking this multiple 2D matrix on top of each other. So, one layer became this. Similarly, you have made another layer. This is your second layer. Similarly, you have made a third layer. This is your third layer. Why three layers? Because see what we have. What is written here? 3, 3, 3.

  424. Speaker 2

    Right? That means you have three 2D metrics also. See this. Three rows, three columns. And let's say this.

  425. Speaker 1

    What can we call the third dimension after rows and columns?

  426. Speaker 2

    Let's call it depth. Right? So depth is also 3. So see.

  427. Speaker 1

    Three rows. Three columns. And you assume that this is on top of this and this is on top of this. So it becomes a cube. So you can represent a 3D matrix conceptually. Although 3D matrix is very uncommon. No one uses it that much. But if you understand 3D matrix, then you will understand 4D, 5D and so on. You can declare any ND matrix. So we say in Java that you can declare a multidimensional matrix. You can make a multidimensional array. But generally, we mostly go to a two-dimensional array. Sometimes, to solve a problem, we need a three-dimensional array. But maybe we go beyond that. Because it becomes very complicated to understand things. But yes, you should know that you can do this.

  428. Speaker 2

    Okay? Very good. Now, let's write the last thing. Till now we were.

  429. Speaker 1

    Understanding all the arrays, like first of all let's talk about 1D array which was our 1D array So we saw only one way to display it, let's say we wrote roll numbers roll numbers and we wrote equal to new int and gave a size, let's say 3 You can write something like this instead of this int roll numbers And you want that you don't declare new int 3 first, that you make 3 size array and then add value to it one by one. Because look, let me show you in this first. What did you have to do to add value? You had to do like this to add value that roll numbers of 0 equal to let's say 4.

  430. Speaker 2

    Then roll.

  431. Speaker 1

    Numbers of 1 equal to let's say 5. You do something like this. So on the other hand, you can write like this too. How can you write? Something like this that int sorry int bracket role numbers equal to and give a curly bracket and don't put its values here 4,5,6 and close this curly bracket and put a semicolon you can also declare your array in this way So here we didn't write the size, like we wrote 3 size here, we didn't write the size here, we just wrote 3 values here. So your compiler will determine by itself that what to do is to make an array of 3 sizes whose values are 4, 5, and 6.

  432. Speaker 2

    You can do this too.

  433. Speaker 1

    Remember, if you already know the size of the array, I mean, the size will obviously be known before, but if you already know the value, then you can declare it in this way too. And you can do the same thing in a two-dimensional array too. What you have to do in that, you can write int, you had marks, marks equal to now make a two dimensional array, how? you can write like this, marks 4, 5, 6 then curly bracket 7, 8, 9 Let's say 23, 34, 93, whatever random values I have added. So you can fill values in a two-dimensional array like this. Open a curly bracket and close it. Define each row one by one. So this is row 1, row 2 and row 3. Something like this.

  434. Speaker 2

    Okay?

  435. Speaker 1

    Same, you can do it for 3D, you can do it for 4D, you can keep doing it like this. So, these are also ways to declare your array and define it along with it.

  436. Speaker 2

    Okay?

  437. Speaker 1

    If you don't want to use that new keyword and don't want to use them separately.

  438. Speaker 2

    Okay? Now, whatever we have seen, let's quickly go and see it in code. Yes.

  439. Speaker 1

    So, till here, we had seen our one-dimensional array.

  440. Speaker 2

    Very good.

  441. Speaker 1

    Let's do one thing. Let's quickly make a new class. Let's say demo2.

  442. Speaker 2

    Java. Okay?

  443. Speaker 1

    And this is so that we can see our multidimensional array in a different class. Okay, so let's write our boilerplate code in it. And now let's start. So here we are going to start with our multidimensional arrays. Okay, very good. Now let's see multidimensional arrays. First of all, what did I say? I make a multidimensional array, marks.

  444. Speaker 2

    Okay.

  445. Speaker 1

    Equal to new int And I make an array of 3 x 3 Which we saw earlier And we can add value in it Like this Marks of 0, 0 Let's say I added 23 marks here I am adding random marks You can also take marks from table 0, 1 I added 25 here And marks of 0, 2.

  446. Speaker 2

    And I have also put 45 here. Something like this. So I have put all of them in the rows of 0.

  447. Speaker 1

    By doing this, I can put all of them in the first row as well. And I can put all of them in the second row as well.

  448. Speaker 2

    Okay.

  449. Speaker 1

    So this is 0,0. Now this is 1,0, 1,1 and 1,2. And here we have 2,0, 2,1 and 2,2. Let's change the marks of all of them. 34, 11, 9, What happened? 2, 0, 2, 1 and 2, 2 happened. Let's change some of these marks.

  450. Speaker 2

    34, 11, 90. I'm adding random marks. 56, 23, 78. Okay. So, I added marks in this array.

  451. Speaker 1

    And what I said was that I can print them by putting a loop. So, first of all, let's say I write row equal to 0. Row less than 3.

  452. Speaker 2

    Row plus plus. Okay.

  453. Speaker 1

    And again, here comes the row. And again, in inner loop, I can write int col equal to 0. col less than 3 because size is 3. And col plus plus. Something like this. And I can print all of these. System dot out dot. First, let's print so that there is only one print in one line. Sorry, all of them get printed in one row. So, my array name is marks.

  454. Speaker 2

    Whichever row it is.

  455. Speaker 1

    Print all the columns and give some space And after this loop, I will put one println so that it comes in the next line after every row This is what we talked about in our program So our output should be like this that it will come in the first line 23, 25, 45 Then these three will come in the second line and these three will come in the third line So let's run it once Look at this.

  456. Speaker 2

    Absolutely correct, isn't it? The way we had expected. Okay, very good.

  457. Speaker 1

    Okay, second thing. Do we need to write row less than 3, column less than 3? We had talked about this, right? I can directly write here our array's name, marks.length.

  458. Speaker 2

    Absolutely correct.

  459. Speaker 1

    And what can I write here? Here I can write marks of length. The array is of the dot length of the roweth array. We talked about this, that the array of the marks is different conceptually, but how will it be stored physically and logically? So what we will do about it, the array of the first marks, means we will call this one marks of 0, this one marks of 1 and this one marks of 2. So, marks of 0.length, marks of 1.length and marks of 2.length. So, what I have written in short is marks of row.length. If we do this, then also our array will be easily printed.

  460. Speaker 2

    Absolutely right. Very good. Okay, I had told you.

  461. Speaker 1

    That the first one is It represents your rows and then we represent columns. So this is rows and this is columns. And columns are optional. So I can remove it. Now I want to store that array in a 2D array whose number of columns are different in each array.

  462. Speaker 2

    So I can do something like this. First of all, let's move forward. Let's make it 3 for now.

  463. Speaker 1

    We will comment it so that we can keep all things together for you. So I commented it for now. Now let's go down slowly. And let's start again from here. Now see there is nothing above. We are starting everything again because I want to make a multidimensional array but with each with different length. So first of all I made an array of marks.

  464. Speaker 2

    Let's say marks equal.

  465. Speaker 1

    To This is a two dimensional array so I have to declare it twice. Marks equal to new int Something like this. And let's say I tell 3 rows. That number of rows. That number of rows is 3. Number of rows is 3. But I haven't told columns yet. Now see how I will make columns. I will make marks of 0 array. Its length is 2. Or let's say 1.

  466. Speaker 2

    Okay.

  467. Speaker 1

    Marks of 1 array. Its length is 2. and the length of marks of 2 is new int of 3. So basically, how did I tell you? If I visually imagine it, then I would have told it like this, that my array would look something like this, that here will be an element, sorry, here will be an element, and here, sorry, here, and here will be an element, similarly here, and here, And there will be an element here.

  468. Speaker 2

    Right? In this way, I will be saying something.

  469. Speaker 1

    That the length of the first one is 1, the length of the second one is 2, the length of the third one is 3.

  470. Speaker 2

    Right? Okay.

  471. Speaker 1

    So, I fill the value in this. So, how can we fill the value? Now, obviously, I know that I can write marks of 0, 0. Because there is only one length in this. So, 0, 0 will come. Let's suppose I filled 23.

  472. Speaker 2

    Right?

  473. Speaker 1

    Now, can I write marks of 0, 1? Can I write like this? Absolutely not. Because 0,1 is not valid. Its length is 1. So, error index out of bound exception will come. We will see that exception later.

  474. Speaker 2

    Now, I can write next 1,0. Okay. 1,0. So, let's write its length. Let's say 24. Can I marks of....

  475. Speaker 1

    Can I write 1,1? Yes, I can write because I have a size of 2. So, let's say I wrote 90 in this.

  476. Speaker 2

    Very good. Now, I will write marks of 2,0. Because I can't write 1,2. So, 2,0.

  477. Speaker 1

    Let's say I wrote 12 in this. I can write marks of 2,1 too. I have added a value of 78 in this. And in fact, I can write marks of I can also write 2,2.

  478. Speaker 2

    Why can I write?

  479. Speaker 1

    Because its length goes up to 3. So, I wrote 2,2.

  480. Speaker 2

    Let's say 45. Very good.

  481. Speaker 1

    I can't write 2,3. I have added all the values. Now, I can print it. And again, I will do the same way of printing. I will do one thing. I will copy.

  482. Speaker 2

    This. Okay. Here. And I will do this. Uncomment. Like this.

  483. Speaker 1

    So again, I go to row equal to 0, row less than marks dot length or row plus plus.

  484. Speaker 2

    Okay.

  485. Speaker 1

    So every time I go to rows. And in every row, I go to the length of the columns. So basically, if I make it again, what I said, how will my array look like? So in my array, first will be one element. In the second, there will be two elements.

  486. Speaker 2

    Okay.

  487. Speaker 1

    Something like this. And in the third, I will have three elements. Something like this. So first let's say value will be 23, second will be 24 and your 90. And third value will be 12, 78 and 45.

  488. Speaker 2

    So this is how my print should be.

  489. Speaker 1

    First I have brought my flow of control here, row is equal to 0, row.

  490. Speaker 2

    Is equal to 0.

  491. Speaker 1

    Then I will go to inner loop of this loop and I will say, run column from 0 to marks of row.length.

  492. Speaker 2

    I.e.

  493. Speaker 1

    From 0 till the length of this row is attained. And what is the length of marks of 0? The length of marks of 0 is 1.

  494. Speaker 2

    I.e.

  495. Speaker 1

    I will print only one element, 23. Then again, I will come out of this loop on the new line. Then again, the value of the row is 1. Again, I will come to the inner loop. I will say, this time, how far should I run this column? marks of row.length, i.e. marks of 1.length. And what is the length of marks of 1.length? It is 2. So again it will go till 2, so it will print 24 and 90, which was written here. Okay, then again it will go for 3rd. And this time marks of 3 dot lengths will go. How many 3 dot lengths are there?

  496. Speaker 2

    There are 3. See, I have even written it. Sorry. How many marks of 2 are there? 3. Means new int 3 size. And see, I have put 3 values in 3 size.

  497. Speaker 1

    I will separate it. This is my 1. This is my first row, this is my second row and this is my third row. So the value is 12, 78, 45. So I have printed it here. So my output should be like this. So let's see it quickly. Okay, so see it is exactly 23, 24, 90, 12, 78, 45.

  498. Speaker 2

    So, my output is something like this. Okay?

  499. Speaker 1

    So, I hope you understood that how we can print different size of the array, which is a multi-dimensional array, how we can play with it. You can apply the same concept if you want to make a 3-dimensional array or a 4-dimensional array. It's the same concept. And let me show you once that I can declare the array like this.

  500. Speaker 2

    How?

  501. Speaker 1

    As we discussed in the last video. Something like this. If I talk about 1D array again, So I can do it like this. Let's say int roleNumbers equal to new. By writing new int, I can directly mention the role number here.

  502. Speaker 2

    Like 101, 102, 103.

  503. Speaker 1

    Something like this. So I can do this too. In fact, I can print it like this too. i equal to 0, i less than roleNumbers.length roleNumbers.length length i + + And every time what I do is system.out. println to our roll numbers of i something like this so our 101,102,103 will be printed in a new line see this is perfect and same concept I can do for a two dimensional array I can also do like this that the int of our marks array equal to new int sorry I will put it like this in my curly brackets and in every curly brackets let's say I will make a new row like 12, 14, 56. This is a list of 1 marks. Similarly, 24, 45, 67. This is a list of 2 marks. Here, comma will keep coming obviously. Comma and my 1st row is left. Let's say 3rd row. So here, 45, 67, 78. Something like this. I can define the marks in any way. This is my two-dimensional matrix. And I can print them in the same way. In the same way that I was doing till now. The way I was printing my two-dimensional matrix.

  504. Speaker 2

    Too. Let's write here that this is a 2D matrix. Or an array. So, I can print this. So, this will be printed on the screen. Let's do it once. See, it's done.

  505. Speaker 1

    12, 14, 56, 34, 45, 67, 45, 67, 78.

  506. Speaker 2

    Okay.

  507. Speaker 1

    So, you must have understood how we can represent in this way and using new keywords which we were doing before that.

  508. Speaker 2

    How we can do that using this. Okay.

  509. Speaker 1

    So, I hope you understood arrays well. Rest, all the questions that you have uploaded on GitHub, you have to practice them on arrays. Your concept will be more clear. Now, let's move on to the last topic of the video which is a small topic which is called strings.

  510. Speaker 2

    Okay. Yes.

  511. Speaker 1

    So now we are going to talk about Strings in Java Strings itself is a very big topic And you will understand Strings better when we will talk about Object Oriented Programming in Java Because Strings are also a non primitive data type In fact, before that let me tell you that what we were reading till now Remember we had discussed about data type And we had said in the beginning that we have primitive data types and non-primitive data types. Okay, you must remember. And in primitive, we talked about different data types. First, we talked about integers, in which your byte, short, int, long, all these come. Then we talked about floating point numbers, like your float and double come. We talked about boolean, we talked about char, and etc., Apart from this, we call all the data types as non-primitives. You will understand non-primitives when you have object-oriented programming knowledge. But you can assume that non-primitives include your arrays, strings, and many other things like objects. But you don't have to focus on all these because we haven't read all of them yet. But now I will tell you about strings because strings are a data type that.

  512. Speaker 2

    We have been using for a long time. But you don't know that we call it strings. I will tell you how.

  513. Speaker 1

    First of all, if I write string, let's say str or give it a proper name. First of all, I have to write data type and my data type's name is string. Here comes the data type. And let's say I write its name name equal to. I write any name here and end it with a semicolon. As soon as I wrote string, it means that I am telling our compiler that whatever value I am going to put in this container, it is a string type. Now string can be any line. For example, I have written my name here, so let's say I have written the name Aditya. And again, you always put any string in a double quotation.

  514. Speaker 2

    Something like this.

  515. Speaker 1

    As you remember, you used to write char char c equal to a. You used to write in a single quote. Similarly, you always write a string in a double quote.

  516. Speaker 2

    Aditya.

  517. Speaker 1

    So, what did I tell the compiler? That I have to declare a name whose value is Aditya. So, again, what will happen? A container will come. The name of that container will be name. And what will be the value in it?

  518. Speaker 2

    Aditya.

  519. Speaker 1

    Let's say I call it fname instead of name And I can also make another string lname meaning last name And I can write another string in it Let's say tendon Something like this So, I can declare any string in this way. Now, we will not go into the operations of the string. Because we will understand all that better when we will study the strings in-depth after oops. Now, we just want to understand that we can declare the string. So, now see I have made two variables fname and lastname. In fact, whenever I write system.out.println Whenever I write something in it, it is always of string type.

  520. Speaker 2

    Right?

  521. Speaker 1

    That's why you see that I sometimes write it in double quotes. If I want to print a hello world, let's say I want to print a hello. So what do I do? I put it in a double quote. Because double quote means a string. So I am telling the compiler that I want to print a string whose name is hello.

  522. Speaker 2

    Okay?

  523. Speaker 1

    Let's say I want to print Aditya Tandon together. So either I write Aditya Tandon here. But because I have made two variables for it. So what can I do? I can write system.out.println and I will write fname first. So my first print will be aditya. After that, I have to print tendon. Now, to print aditya and tendon together, I have to concatenate this first name and last name variable. Concatenate means to join them together. For that, I have operator plus. So, I will write fname plus lname. And here plus doesn't mean to add them. Whenever you add plus in strings, then plus means to concatenate the first name with the last name. That means to add them together. So first you write Aditya and then add the tendon together. That's all it means. If you understood this well, then you can use strings well. But yes, We won't tell you the internals of strings, we will learn that when we will learn the strings in depth. So let's quickly see this in code and end this video. So let's quickly see our strings. Let's say I declared a string first name. I gave it full available first name.

  524. Speaker 2

    And what did I say?

  525. Speaker 1

    It comes in double quotes. So I can write aditya here. Similarly, I can declare a string. Remember, the last name of the string will be S. And I can add my surname, which is Tandon. Now, I can print this. So, I can write system.out.println And here, I can combine my first name and last name.

  526. Speaker 2

    First name plus your last name. Now see, I said first name plus last name. Now when it will be printed, do you know how it will print?

  527. Speaker 1

    It will print aditya and without giving a gap, it will write tendan because I didn't give a gap between these two.

  528. Speaker 2

    It doesn't know that I have to give a gap by itself.

  529. Speaker 1

    Neither there is a gap in front of aditya nor there is a gap before tendan. So it will print it like this. So if we see it, See, it printed without a gap. If I want a gap, what can I do? I can add a gap and a lastname. Because remember, this is also a valid string, lestne mainne lala htr equal to this.

  530. Speaker 2

    This.

  531. Speaker 1

    Only a space is a valid string. In fact, leave the space.

  532. Speaker 2

    What is this? An empty string. This is also a valid string. Okay.

  533. Speaker 1

    We will read about this in depth later. But now see what I did. First name, space, last name. Now here first name, then space will be printed and then last name will be printed. And now see how our output will come. Proper Aditya Tandon came. Right. So this is what we had to read about strings. In fact, by concatenating this, we can add our own variable. Like I wrote a variable full name. And in that I wrote first name. plus space plus last name. I have also put this in a variable whose name is fullName. Now here I can print fullName directly. Something like this. So what I did is, I took a variable, like you add integers, if you add 2 and 3, then you write 2 plus 3. Here I am not adding integers, I am concatenating strings. So this is also a variable operation. Sorry, it is an expression, so I wrote firstName plus space plus lastName, put it in fullName. And fullName will also become a string. And print this string. So still my Aditya Tandon will be printed. So that's all you need to know about strings. After that, when we will study in depth, you will be able to understand a lot of things.

  534. Speaker 2

    Rest, again, this video is also quite long. That's all in this video.

  535. Speaker 1

    See you in the next video. Till then, thank you so much.