Not look at the data structure called it is software it gets lot of its power through data structures 2
that it uses and the data structure is an organized collection of related data. 3
For example if you want to print all the CT status that a student has registered for then watch this 4
course titles in some kind of a data structure before printing them later. 5
You look at several of these powerful built in data structures. 6
However there is one very basic data structure that is built into every programming language and it's 7
an art. 8
In fact it is so basic that even some of the data structures that we study later are built on top of 9
arrays pre-knowledge just look at arrays and we will study other data structures later. 10
And that is basically a container object that holds a fixed number of values of a single type. 11
Some of the terms in this definition are emphasized in bold. 12
And let's understand what they mean. 13
The term object in this definition implies a Java object that is in Java. 14
An array is basically an object and hence will be stored on the heap like any other object. 15
Since R is an object the variable referencing it is an object reference next to a fixed number which 16
means that the number of items they can store is decided at the array creation time itself and cannot 17
be changed thereafter finally by a single type we mean that the items in an RV should be of a single 18
data type like N and R double or even some class that is an array can store primitives or object or 19
Francis but only condition is that they have to be of the same type. 20
Here is an illustration of an array which contains seven integer values. 21
Each item in the array is called an element and this axis by its next number an index number is nothing 22
but the numerical position of the element in the ID and index numbering begins with zero. 23
Now if this array is named as my array then the fourth element which is a value 5 is accessed in this 24
way. 25
That is you will have the Aryanism followed by square brackets with the index number in between the 26
square brackets. 27
Multiple axis. 28
Fourth element the next number will be three as index numbering starts with zero. 29
No coming to creating an array there are three ways to do it. 30
Let's look at how we can create our example or a call to my at it. 31
Let's just look at the case where an arrest or primitives later we will see an example where underresourced 32
object references and hit is a fast way to do it. 33
We use the word new knew the number of elements that are it would store is indicated in square brackets 34
. 35
This declaration is quite similar to the declaration we saw for creating objects. 36
The difference is that in this index we how additional square brackets on the left hand side of that 37
assignment are on the right hand side. 38
MP balances is replaced by square brackets since the arrays of pipe and each element will by default 39
be zero that is. 40
Each element is basically an end variable and is initialized with a default value an inquiry. 41
But you can get. 42
Which is zero. 43
So do the R.H. then if it's an object it's elements here are primitives. 44
Next step would be to initialize each element all the seven elements are initialized in this way using 45
their next numbers. 46
The Szilard element is initialized with the value 9 first element with the value 11 and so on. 47
Not since an array is an object. 48
If the other declaration contains only that type under array name then that variable gets the default 49
value. 50
Any object reference gets which is null. 51
Here is the second way to create an array. 52
Syntax is similar to the first approach but with two differences is Element initialization is done in 53
the declaration itself and between the two braces. 54
Second difference is we have empty square brackets on the right hand side. 55
That is we don't explicitly specify the array size. 56
I is automatically inferred from the number of elements used to initialize the. 57
In this case it is 7 specifying that RSS will result in a compile time error. 58
Finally to create an array has a simpler syntax. 59
Right answer in quotes only element initialization. 60
There is no Nuki word order type information with the square brackets. 61
Finally we saw that in all three array creation examples the declaration began with the element type 62
followed by empty square brackets. 63
However it is perfectly legal to also have the empty square brackets after the are in him instead of 64
the element type like we see here. 65
Personally I prefer to have it after the element type and that's because on the right side also the 66
square brackets follow the element type. 67
So it's just for the sake of consistency but it is entirely up to you. 68
Often we need to know the length or size of the army. 69
That is the number of elements or array contents. 70
And for this we can use the length of the ID that is left is a feat within the array object as an array 71
is an object as we already discussed. 72
So for our miring example accessing lanthanum my very variable returns the value 7 we know that aria 73
has a fixed number of elements and so accessing an element outside of the boundary will result in an 74
added runtime. 75
For example my idea has only seven elements and so trying to access elements beyond the seventh element 76
really do are on parameter in this example. 77
We are trying to access the eighth element which is stored in next number 7 and it will result in a 78
runtime error. 79
So we looked at arrays containing primitives but arrays can also store object references. 80
And here is an example similar to an array of ends. 81
We can create an array of object references here and article students is created which can store boost 82
with an object or Francis as you can see the type of the R is simply changed from end to student. 83
Since each element is an object reference but default each element gets initialized with no. 84
Since each element is an object reference we can initialize each element by assigning a new student 85
object. 86
So each element no references that student object on so we can also initialize each element state in 87
this bit using the dot operator. 88
So basically arrays can store either primitives or object references on be no understand how it can 89
be done. 90
Now let's discuss a bit about how arrays are represented within memory Gibeon specification doesn't 91
say anything about how an object is stored inside memory. 92
Hello. 93
It is generally believed that most GBM implementations use a mediately out when it comes to. 94
That is that our elements are stored contiguously. 95
In other words they are stored next to each other in the memory. 96
And this and also fast random access. 97
There is any element can be accessed in in constant time. 98
So accessing Tozan element would take the same amount of time as accessing the fifth element the element 99
access is extremely fast if you want to search for a particular item in the array. 100
Then that would be linear time as we have to scan the directory starting from the first element. 101
Later we would look at data structures that are designed specifically for fast searching not just look 102
at a very simple and quick them off our list. 103
OK in this demo we're going to fill up this new method called arrays and it's in walk from the main 104
method and all the previous method invocations have been commented out. 105
So we'll be just testing fewer things here. 106
One is we'll create an array using the second approach that we solve for creating arrays. 107
Then we will use the lenth function lengthy and really does that. 108
And then we would also look at how we can access the elements right. 109
We can use it. 110
We can access the elements using and mixed numbers and we would also apply order. 111
So it's going to be a really simple demo. 112
So just go ahead and create the array and we will create the exact same idea that we have seen earlier 113
. 114
So let's just call it and followed by Grad rockets. 115
Let's just call it my theory as we have seen in this light. 116
It's in you and in the second approach. 117
We'll have this kind of an operation followed by basis and we are going to initialize the elements right 118
here in the declaration. 119
So I have just copied that. 120
So those are those are the same elements not just put in some of the things system not all or brindled 121
and to just turn the Leonti just so let's see my re. 122
Them niggas copy this. 123
So this is going to print the size of the ID next leps access of all of the elements. 124
So let me just copy this whole thing. 125
It's axis the second element which is Axis using the element and next number one. 126
So let's just go ahead and compile and does this by it's fine. 127
So there you go. 128
So we are inside our base. 129
The ideal to 7 and the first the second element is basically 11. 130
OK. 131
This is what it is not it's just trying to access an element which is outside the boundary of I. 132
So the idea has seven elements so let's just try to access the 8 element which is accessed using the 133
next number 7. 134
It's really compiled and this should give a runtime error and that's what we get here. 135
It's this array index out of bounds exception. 136
So we are getting a runtime error. 137
And that's because we are trying to access something outside the boundary of the ID. 138
OK so those are three simple things here. 139
And so we now have an understanding of this. 140
So the main thing that we need to remember about arrays is an arm is basically an object in yellow. 141
OK I it will have a fixed number of elements. 142
That's one thing I and all the elements should be of single type. 143
In this case it is and but it can also be object references. 144
So later in the project Beeville in the first version rule extensively use arrays undir we will we will 145
try we'll create lot of ways that store object references. 146
OK unjaded We will also look at other data structures sophisticated radar structures and that's about 147
it. 148
So just go ahead and you can find the updated basics democracy in the resources section and you can 149
now download and exit this file it's a good program and you can play around with that. 150
OK then. 151
Thank you. 152
And happy coding.