Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,460 --> 00:00:04,059
We can use two dimensional arrays to store data that come in the form of a table.
2
00:00:07,550 --> 00:00:13,910
Let's imagine you have a list of grades for one student, Harry, Harry, go to 70 to a 74, a 78 and
3
00:00:13,910 --> 00:00:15,460
a 76 in his courses.
4
00:00:16,160 --> 00:00:21,290
Now an array of integers can easily store this list of data, but what if there are more students?
5
00:00:21,560 --> 00:00:23,110
This data isn't a list anymore.
6
00:00:23,420 --> 00:00:25,130
It's a table with three rows.
7
00:00:26,000 --> 00:00:29,450
So it looks like we're going to need three arrays to store each row of data.
8
00:00:36,480 --> 00:00:39,380
OK, sure, that's fine, but what if there are one students?
9
00:00:39,720 --> 00:00:41,540
Are you going to create a hundred a raise?
10
00:00:42,120 --> 00:00:43,350
I sure hope not.
11
00:00:46,510 --> 00:00:52,030
Because when your data comes in the form of a table or a grid, you need to use it to the array, which
12
00:00:52,030 --> 00:00:53,470
would look something like this.
13
00:00:56,380 --> 00:00:59,800
And it's a lot easier to manage one array as opposed to hundreds.
14
00:01:03,960 --> 00:01:07,020
So in this lesson, you're going to learn when to work with two drays.
15
00:01:10,930 --> 00:01:16,960
First things first, create a new file name to erase Java, to erase an inside the class, make the
16
00:01:16,960 --> 00:01:17,680
main method.
17
00:01:25,200 --> 00:01:29,190
So what is it to Deira, a tutera is an array that contains a race.
18
00:01:30,390 --> 00:01:33,960
Two degrees are perfect when your data is in the form of a grid or a table.
19
00:01:37,580 --> 00:01:39,980
Every row in this table is like its own array.
20
00:01:43,540 --> 00:01:49,120
One array can store the first row of data, a second array can store the second row of data, and a
21
00:01:49,120 --> 00:01:51,630
third array can store the third row of data.
22
00:01:52,450 --> 00:01:58,180
But instead of creating many integer arrays to store individual rows, we can bundle this data into
23
00:01:58,180 --> 00:01:59,080
a two Deira.
24
00:01:59,740 --> 00:02:03,130
The studio array is capable of storing every row in this table.
25
00:02:05,300 --> 00:02:10,729
Because this Todora has three rows and each row is like its own array, and we can access each row with
26
00:02:10,729 --> 00:02:12,530
an index that goes from zero to two.
27
00:02:13,250 --> 00:02:18,650
Also each row, each array contains elements with indexes that go from zero to three.
28
00:02:23,850 --> 00:02:28,990
And so in order to create a tutera, you need to write the type of data you're storing with two brackets.
29
00:02:29,520 --> 00:02:32,540
This means we're creating a two tier array of integer values.
30
00:02:33,120 --> 00:02:35,130
The first bracket is the number of rows.
31
00:02:35,310 --> 00:02:37,880
So we're basically creating a table with three rows.
32
00:02:38,250 --> 00:02:41,280
And the second bracket is the number of elements in each row.
33
00:02:41,910 --> 00:02:45,750
In this case, each row of data is going to contain four elements.
34
00:02:49,940 --> 00:02:55,430
And so from a visual standpoint, this code is going to create an array with three rows and four columns
35
00:02:55,790 --> 00:02:58,880
and by default every value is going to start at zero.
36
00:03:03,510 --> 00:03:10,530
Let's try it out inside your glass, create an array with three rows and four columns into grades is
37
00:03:10,530 --> 00:03:12,510
equal to a new integer to Deira.
38
00:03:13,770 --> 00:03:19,380
The first bracket is the number of rows we're going to have three rows, the second bracket is the number
39
00:03:19,380 --> 00:03:23,400
of elements in each row and each row is going to have four elements.
40
00:03:24,210 --> 00:03:25,260
OK, what now?
41
00:03:26,740 --> 00:03:32,500
So we have three rows and each row is basically an array with four elements, we can grab the row or
42
00:03:32,500 --> 00:03:35,470
in other words, the array of values at index zero, one or two.
43
00:03:43,950 --> 00:03:48,270
Now, in our code, we can index each array and print its contents using arrays not to string.
44
00:03:58,960 --> 00:04:00,700
You can print there, right, index zero.
45
00:04:06,770 --> 00:04:09,830
The IRAD Index one and the red index to.
46
00:04:20,940 --> 00:04:25,860
And as expected, each row is an array with four elements, the first array has Harrys grades, the
47
00:04:25,860 --> 00:04:28,350
second one run and the third one her minie.
48
00:04:28,950 --> 00:04:31,200
So I'm going to print some messages to reflect this.
49
00:04:31,200 --> 00:04:32,550
I'll put a tab of space.
50
00:04:35,160 --> 00:04:37,650
Followed by Harry and a Colin.
51
00:04:44,270 --> 00:04:46,700
I'll do the same thing for the next two print statements.
52
00:04:56,030 --> 00:04:56,930
And her mighty.
53
00:05:10,810 --> 00:05:12,690
All right, we're off to a pretty good start.
54
00:05:16,020 --> 00:05:21,870
So how do you update to Dr� values, just like before you can update Arae values from their index?
55
00:05:27,290 --> 00:05:32,510
You can access any item in this table with two indexes, if I want to change your mind is great and
56
00:05:32,510 --> 00:05:35,780
charm's the first index is the area we're interested in.
57
00:05:36,140 --> 00:05:40,100
In this case, Hurum fetching the ROE and fetching the array with an index of two.
58
00:05:40,730 --> 00:05:43,400
The second index refers to the element in that array.
59
00:05:43,820 --> 00:05:49,670
In this case, I'm grabbing the value that's inside row two and has an index of three within that row.
60
00:05:50,980 --> 00:05:54,070
So at this information, I can start by updating Harry's grades.
61
00:05:56,140 --> 00:06:01,560
All of Harry's grades are in the first row, row zero, so the first bracket is going to index the array,
62
00:06:01,600 --> 00:06:03,040
the road that we're interested in.
63
00:06:06,120 --> 00:06:12,660
And we can use the second bracket to index a specific element in zero, Harry got a seventy two in potion.
64
00:06:16,610 --> 00:06:18,290
A 74 in herbology.
65
00:06:21,640 --> 00:06:23,380
A 78 and Earthman, see?
66
00:06:26,340 --> 00:06:28,140
And a seventy six and charm's.
67
00:06:34,300 --> 00:06:35,980
I can go ahead and run the code.
68
00:06:40,610 --> 00:06:44,100
And as you can see, this updates every element in the first story.
69
00:06:44,600 --> 00:06:48,050
Now we're going to do the same thing for a run in her money runs.
70
00:06:48,050 --> 00:06:50,960
Grades are in the second row, the row with an index of one.
71
00:06:51,470 --> 00:06:56,840
So once again, we use the first bracket theory we're interested in and then we can use the second bracket
72
00:06:56,840 --> 00:06:59,270
to index a specific element in a row one.
73
00:07:02,130 --> 00:07:03,990
Ron got a 65 and potion.
74
00:07:05,490 --> 00:07:07,110
A 64 in herbology.
75
00:07:10,790 --> 00:07:12,370
A 61 in Earthman, see?
76
00:07:16,200 --> 00:07:17,940
And a 67 and charm's.
77
00:07:22,460 --> 00:07:25,340
And we can replicate this logic for her Chinese grades.
78
00:07:56,280 --> 00:07:57,450
I can run my code.
79
00:08:02,230 --> 00:08:04,070
And everything works out.
80
00:08:04,830 --> 00:08:10,450
Hope you can appreciate that two ideas are perfect when you want to store a table of data instead of
81
00:08:10,450 --> 00:08:14,240
using multiple one dimensional arrays to store each row individually.
82
00:08:14,530 --> 00:08:17,980
We can use that to Deira to store the entire table at once.
83
00:08:26,330 --> 00:08:31,790
I want to introduce a faster way of initializing to dress, because the code is getting a bit long since
84
00:08:31,790 --> 00:08:36,659
we already know what the values are, we can create the array and define the values in one line.
85
00:08:37,220 --> 00:08:40,640
This code is going to create a two tier with three rows of values.
86
00:08:41,770 --> 00:08:45,670
Each row is an array bundled in a 2D array.
87
00:08:49,680 --> 00:08:51,150
So we'll try this out in our code.
88
00:08:56,870 --> 00:09:01,400
Each arrow of data is basically an array, so we need one array to store Harry's grades.
89
00:09:05,610 --> 00:09:07,440
One array to store runs grades.
90
00:09:25,570 --> 00:09:27,430
And another to store her mind is.
91
00:09:36,260 --> 00:09:37,160
Runner code.
92
00:09:44,700 --> 00:09:48,060
And everything works as it should, the code looks a lot better.
93
00:09:53,550 --> 00:09:56,470
OK, so how do we access each value in a tutera?
94
00:09:57,030 --> 00:10:00,270
Once again, we can access each value using the two indexes.
95
00:10:02,640 --> 00:10:08,520
If I want to access her mind is great and Charm's the first inducts gets the array, it gets the row
96
00:10:08,520 --> 00:10:12,990
with all of her grades and the second index gets the grade that we're interested in.
97
00:10:15,800 --> 00:10:19,550
So I'm going to wrap up this lesson by printing all of their grades as part of a string.
98
00:10:23,540 --> 00:10:28,100
Once again, we used the first bracket to specify the road that we were interested in, all of Harry's
99
00:10:28,100 --> 00:10:33,650
grades are in the first row zero and his potions grade can be found in index zero of the first row.
100
00:10:38,440 --> 00:10:40,480
His herbology grade is an index one.
101
00:10:50,550 --> 00:10:52,080
Earthman index to.
102
00:10:55,840 --> 00:10:57,370
And Charm's Index three.
103
00:11:04,150 --> 00:11:09,010
I can do the same thing with Iran, except that all of his grades are in the second row, row one.
104
00:11:38,030 --> 00:11:40,810
And we can wrap up by doing the same thing with her mind greats.
105
00:11:41,090 --> 00:11:43,310
They're all in the third row row to.
106
00:12:05,590 --> 00:12:10,960
And that's perfect, you created an array that stores three rows of data and then you accessed every
107
00:12:10,960 --> 00:12:13,310
value in this table using the indexes.
108
00:12:14,200 --> 00:12:18,970
We always start with the index of the array, followed by an index for the item inside.
109
00:12:21,010 --> 00:12:27,130
In this lesson you learn to work with, to raise a Deira is an array that contains a race, each row
110
00:12:27,130 --> 00:12:30,430
of values is an array bundled in a tiara.
111
00:12:30,940 --> 00:12:33,380
This makes them perfect for storing a table of data.
112
00:12:33,430 --> 00:12:38,260
That's because each array is like a row inside of a table and you can access any value in the table
113
00:12:38,260 --> 00:12:44,020
using the index as the first index fetches the array that we're interested in and the second index gets
114
00:12:44,020 --> 00:12:45,550
the element inside the array.
11349
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.