• 2 days ago
Transcript
00:00Next time we are going to talk about Multidimensional Array List
00:03As we have Arrays, we have 2D Arrays
00:09We will try to make a 2D Array List here
00:13I want to make this Array List
00:14I want to make this Array List
00:17which is a Main List
00:20The first List 1 is 1, 2, 3, 4, 5 Stored
00:27Then I have a List 2 which is 2, 4, 6, 8, 10 Stored
00:30Then I have a List 3 which is 3, 6, 9, 12, 15 Stored
00:34Look at this, this is 1 table, 5
00:38This is 2 table, 5
00:40This is 3 table, 5
00:42So I want to store the data in this way
00:46What is the process of Array List
00:47In Java, a list that is stored in Array List
00:55How do we define it?
00:56When we define it, I will write Array List
01:00And I will write Array List
01:03So here I usually write my data type integer, boolean or string
01:07But where I have now written
01:09This is an Array List of Array List
01:11In this list, Array List is stored
01:14And here I will put Angular Bracket
01:16I don't need to define which Array List is stored
01:21If I want to define it, I want to write Integer
01:24Then what will happen? It will be fixed
01:26That my Array List is stored in Array List
01:29And what Array List is stored in Array List
01:30And what Array List is stored in Array List?
01:31It is stored in Integer type Array List
01:52So this syntax is stored in Array List
01:55So this syntax is stored in Array List
01:57So this is stored in Array List
02:21And this will be stored in Array List
02:21And then it will be stored in Array List
02:24So let's use this syntax
02:27And after that syntax, we will try to create the main list
02:31we will try to make it in the code. What do I have to do in the code? First of
02:37all, I will make my main list.
02:38Which will be an array list of array list of integer.
02:45So here, the array list of integer type of array list will be changed.
02:49I have made a new array list. I will name it main list.
02:54Main list is equal to new array list.
02:58On the right side, I will not write this thing again.
03:01On the right side, I can only write an array list and initialize within my memory.
03:07Now, what happened?
03:08First of all, if I have to store a list in it, I will create that list.
03:13Like, array list of integers, list is equal to new array list.
03:28I can add this small list in this small list.
03:30I can add 1 to this small list.
03:32Then, I can add 2 to this list.
03:42So, what do I have to create a main list?
03:44Now, my list will define in which 1 and 2 are stored.
03:49In this way, I can create another list.
03:52Array list of integer.
03:56List2.
03:58New array list.
04:01Now, this list2, I can add some elements in it.
04:04I can add 3.
04:07I have added 3.
04:07And I have added 4.
04:10And I have added 4.
04:11And in the main list, I will add my list2.
04:16So, in this way, when I have written a code,
04:18What will happen in internally Java?
04:20In internally Java, there will be a main list.
04:24In this main list,
04:28I will store 2 references.
04:30One reference will be stored.
04:32I will store a list.
04:33And one will store list2.
04:35So, what is this list?
04:37What is this list?
04:38What is this list?
04:39I have stored 2 elements.
04:40Which is 1 and 2.
04:42And in list2, I have also stored 2 elements.
04:44Which is 3 and 4.
04:46So, I have created a structure in Java.
04:49In this way, I have created a main list.
04:50This is my main list.
04:51In this main list, I have stored 1.
04:53And in this main list, my list is stored 2.
04:57Now, I am going to print them once again.
04:59I am going to write a nested loop.
05:01First of all, what do I want to do?
05:03First of all, I want to traverse the main list.
05:05I want to make a list from the main list.
05:07So, I will write for int i equals 0.
05:10i less than main list dot size i plus plus.
05:16This is my main list.
05:17Now, I want to make a current list from the main list.
05:20First, the list is 1 and then the list is 2.
05:22So, I will write here.
05:24I will write array list of integer.
05:27My current list is equal to main list dot get i.
05:34When I am doing main list dot get i,
05:36I have no integer.
05:38I have the entire list.
05:40I have the entire list.
05:40Because in the main list,
05:42I have a list stored in the main list.
05:44I have the entire list.
05:45I have the entire list.
05:46I have stored in the main list.
05:48Now, I can run the current list on the main list.
05:50For int i equals 0.
05:52i less than current list dot size i plus plus.
05:56So, what do I do here?
05:57I will put it in the main list.
06:00I will put it in the main list.
06:00I already use it in the outer loop.
06:02I will put it in the main list.
06:05I will print it in the main list.
06:08So, i will take the current list.
06:10That means current list.
06:11i less than current list.
06:12Get j.
06:13Add space in this code.
06:17First of all, I have stored a list from the main list.
06:21I have printed all the elements of that list.
06:24Then the second list came again.
06:27Then I have printed all the elements in the next line.
06:31Let's save this one and now run.
06:35First of all, I have printed all the elements of 1 and 2.
06:39Then I have printed all the elements of 2 and 3 and 4.
06:42If I print directly the main list here,
06:47I have this whole structure.
06:52This is my proper main list.
06:55In which there is 1 and 2,
06:57in which there is 1 and 2,
06:57in which there is 3 and 4,
06:58in which there is 2 rows.
06:59This is a 2D array structure.
07:02The array is the size of the outside.
07:06In which there are 2 rows.
07:09So I can imagine these 2 rows.
07:13Now if I have to make the list
07:14which I have mentioned to make,
07:16that is this list.
07:18What should I do for this?
07:19In my main list,
07:21I have to store the list 1,
07:232,
07:24and 3.
07:25I have to store these particular elements.
07:28Then I have to write code.
07:30I have made my main list.
07:32ArrayList of ArrayList.
07:33Now I have to make 3 lists.
07:35So I will make these 3 lists.
07:37ArrayList of Integer.
07:41List1 is equal to new ArrayList.
07:46This is my list 2.
07:47And this is my list 3.
07:52Now I will run a loop.
07:53For int i equals 0,
07:55i less than,
07:56or i equals to 1,
07:59i equals 1,
08:00i less than equal to 5,
08:02i++.
08:02What are I doing?
08:05I must have done in list 1.
08:06Can I add I I I into 1.
08:09Or can I say this?
08:11I must have done
08:12quindi i into 1.
08:14For list 2 to add i into 2.
08:19For list 2 I must have done i into 2.
08:23And I must have done i into 3.
08:26How did I get this? I know that I had to add 1, 2, 3, 4 and 5. So if
08:32I multiply 1, 2, 3, 4 and 5, then I will have 1, 2, 3, 4, 5.
08:36I know that I had to add 2, 4, 6, 8 and 10. So if I multiply 1, 2, 3,
08:424, 5, then I will have 2, 4, 6, 8 and 10.
08:51So if I multiply 1, 2, 3, 4, 5 by 3, then I will have 3 to 5. So in
08:57this way I have added 3 elements in single loop.
09:01Now what I will do in my main list? I can add. First I will add my list 1.
09:09Then I will add my list 2. Then I will add my list 3.
09:18As I have added my main list 3. Now I will print my main list 1.
09:28Let's save and now run. After saving, this first list 1, this list 2, and this list 3.
09:38Now to print it, if I have to write nested loops, how will I write it?
09:43First I will traverse the outer loop through the main list.
09:46I is equal to 0, I less than main list.size.
09:51I++. Then what I will do? I am going to write.
09:55First I will write my current list.
09:58ArrayList.ArrayList of Integer.CurrentList.
10:05I will do this.
10:07I will do this.
10:07MainList.GetI.
10:13Now I will run a second loop.
10:15For Int.
10:16J equals 0.
10:18J less than.
10:20CurrentList.size.
10:22J++.
10:24And what will happen here?
10:25I am going to print my currentList.getJ.
10:37NextLine.
10:38So let's do this.
10:39Save and run.
10:42Now all of these elements are in individual lists.
10:45Now all of these elements are in a single line.
10:46And the same elements are printed.
10:48So many cases will come in which we will try to make a multidimensional ArrayList.
10:53And this is the multidimensional ArrayList.
10:55It is not necessary that every list of each list is the same size.
10:58If I want to do this, what will I do?
11:03I will delete two elements within the list.
11:05So list2.remove.
11:08I am going to remove it.
11:10List2.remove.
11:13SecondIndex.StoredValue.
11:15Save and now.
11:16Run.
11:19So what happened here?
11:20This time my first and last list are in 5 elements.
11:24In the left list, there are 3 elements.
11:26So this is also valid.
11:27It can be a main list in which the first list is one element.
11:31In the second list, there are 2 elements.
11:32In the third list, there are 3 elements.
11:34So internally, the elements of the list is also variable.