Hi there. 2
Now let's look at another class from the jackpot out Udal package which just called us artists. 3
So we looked at tons of they walked us in this chapter and now let's go back to our old unreliable friend 4
which is an art. 5
The class Arias is a generic utility class and it helps us in manipulating memory through its various 6
methods. 7
It has methods which can help us can work on our end to an idealist. 8
Similarly it also has methods that can help us sort of through our search for an element in an eddy 9
or even make a copy of an array or compare it to our race to see whether they're identical contents 10
. 11
So it has lots of useful utility markets and in July 8. 12
So what are the new methods that support bodyless operations have been added with this class. 13
But in this class we will focus on only its core methods which are sequential. 14
But in a subsequent lesson they will look at the paralyzed methods befre. 15
Finally note that most methods in this class how overloaded with sions to support race of different 16
pyramidal types. 17
Also you will see overloaded methods that big arrays of object by present. 18
In this demo we will mostly focus on methods that are in our ideas of object By-Passed parameters other 19
overloaded motions look in the CMB. 20
So let's go ahead and look at what this class has to offer. 21
So here we can see that the R is glass is from the door Trudel package and a new class called is devil 22
has been added to the elections package on that than this I raised a glass. 23
We have the sequential order so that we can demonstrate all sequential operations in this response. 24
So here I have already written a lot of code here. 25
So we want to demonstrate many of the methods in this class. 26
So in the interest of time I wonder did it end up in locations. 27
So we don't have to write any code now. 28
OK. 29
Because I predict all of nine so just go ahead and look at all of the code that I have already written 30
and I'm going to blurt very strongly very clearly so that we can look at each method in a very clearly 31
. 32
So the first method that we want to look at is as a list and this is probably the most commonly used 33
method which you will use from this class and what this method does is as the name indicates it takes 34
an input re and it returns a list list B. 35
So it is saying that give me a list view of the right. 36
So here we how string are it. 37
Let's look at this definition. 38
So this is the awesomeness. 39
And here we have a wad of spectrometer and we know that this is a generic notation. 40
So this is a type and we are saying that the return list should also how elements of that are in here 41
. 42
We are creating a string array and passing that string as an input to this method as honest and it reads 43
a list of strings and intermediate and so on our list. 44
But the thing is this other list will be off fixed sites. 45
OK so that's the most important thing. 46
So always remember this thing if ever you want to convert an array into a list and do not eat less than 47
you would use this method as a list. 48
OK. 49
Just always keep that in mind since it is an idea we will use to address costs. 50
Here we are printing the strengths. 51
So let me just run this case or it prints Rajan on it. 52
So there's a list. 53
Now it's a fixed size list and what it means is that you cannot remove an element or you cannot identity 54
make. 55
If you try to do that the return on their list will throw an error. 56
OK. 57
So let's also try that. 58
Let me just remind you to try to run it as you can see it says unsupported operation exception. 59
So the written order list is not going to support this anymore operation. 60
As soon as we can walk it it will through an unsupported operation exception. 61
And here it is. 62
X is not the same thing happens with. 63
I'd also let you go. 64
But you can actually update the value. 65
That is fine. 66
So let's update the 0 8 value value John and that would reflect in the order you're not added to. 67
So this other list is backed by the original not it. 68
So let me just print that. 69
So as you can see here we are printing and Ari does the original array a latte and it is printing the 70
updated values. 71
OK. 72
John I 90 earlier it was rajin on it. 73
Now here I'm using this method called just to string from the artist class itself. 74
So the string method will take an array and will return a string representation of the elements so it 75
will concatenate all of the elements using comma. 76
And it really and goes it in and square brackets on to display the output. 77
Search says that's returns a string the presentation of the contents of those mystified. 78
It's all there does. 79
So we will be using this tool string method from the IRS class in this Demel. 80
Now let's go ahead and look at more of the methods. 81
So here we know that it returns a fixed size order list. 82
Now if you want to take an RV but if you want to idlest to be modifiable then you could use something 83
like this so here all we are doing is to shift goal. 84
So we are still invoking the as just matter which we're done at a fixed size idlest that is being passed 85
as the input argument to the idlest constructor. 86
So there is a constructor which were big this collection has input and we are simply passing this on 87
to this. 88
So now once you do that you can modify the resulting string. 89
Now the strings as it will be it will be modifiable eyewitnessed. 90
So that's how you would create a modifiable list from an input. 91
Now the ostlers method we know it takes a lot occiput ometer. 92
So it's sort of passing or not it. 93
We can also pass Comus operator lists so that we don't so much problem. 94
So here we have seen that the Azi just matter is taking an input array which is already populated. 95
Now let's say we just want we don't have any idea but just popular with data but we simply want to create 96
an other list of fixed size. 97
Then here is the idiom we can follow this. 98
So here when we say as a list and we are passing a string array. 99
Which means the resulting idlest should include strings and we are saying the size should be three. 100
And this gives greater done or not a list of fixed size. 101
And this does not have any elements. 102
So it would be nullable Yes it would be filled with not. 103
And it is a fixed size. 104
So that's how you do it. 105
If you recall the idlest class is orderless constructor. 106
There was one constructor which takes capacity as input. 107
But if you use that constructor it would create an order list of that capacity. 108
But as soon as the capacity is reached the other the size will be automatically increased. 109
OK so it's not really a fixed size idlest. 110
So if you do that you wouldn't get it fixed size or it is. 111
So if you want to create a fixed size artists and this is the idiom that you need to follow next. 112
Now let's look at one more example grid example here. 113
So here we have this other list as list and we are using an end. 114
So this is an object or ELF object. 115
But here this is an hour off. 116
And so this wouldn't work. 117
So you cannot expect that it would return a list of integer and that's because this new age of two is 118
not auto boxes. 119
OK so you it will knock on what this Indu new in digital. 120
If it was new in digital photo then it would work fine. 121
OK. 122
So let's just make this new integer in that case it does fine but it does just primitive then it will 123
not work. 124
And we knew we already know the reason for that because in auto boxing you recall our auto boxing lesson 125
we said that arrays are not auto blossomy which means that this will not be converted into new off integer 126
offered. 127
So because of that property This assignment will not look to be get a compilation error but this would 128
still work. 129
So if you have something like this as list new and off to denigratory done and list off in digerati 130
. 131
So this would create an idealist underground how only one element which would be an ID and the size 132
of that is true. 133
That is fine. 134
Let me just print this. 135
So as you can see the size of this of a fixed fixed let's do is 1. 136
So that's about as list not it's more to the next category of models which is soc. 137
And let's look at two soft methods one of them is sacque undertakes an object array under it and so 138
why it and this particular method uses a much sought bit natural oddity which means that the idea that 139
the elements should have implemented compatible interface. 140
Now the specification also says that effort is partially soccer at it. 141
If this idea is already partially sorted then we would need far fewer than analogon comparisons and 142
logging to compare results. 143
Mozart needs analogon but it will be far fewer than that if it is partially sawder and if it is almost 144
soldered it would be approximately and comparisons only where n is the precise. 145
So let's go ahead and run this string array. 146
I mean common this out from here. 147
As you can see it prints on it donjon. 148
So it has been. 149
It has already been sorted out. 150
Now there are some additional comments that this particular makes. 151
It says that it is well suited for merging two or more socket ideas. 152
So if you have two or more arrays which are already sorted then the way you would much them on your 153
website as you would simply concatenate the address and then sort the resulting at it because they're 154
already partially. 155
Each of the ideas are already sorted which means which means the munged entries are partially sorted 156
. 157
So we have a much faster way to sort the much edit so the resulting ID will be sorted in a very efficient 158
way. 159
So that's with an object array no lips sought an ID. 160
OK if it is an array of primitives then the saut method would use a quick song. 161
So let's here we have a new array and it has these three elements. 162
So if I run it. 163
So the elements are Saltaire. 164
OK and once again we are using the string method and passing the IRA I know as I mentioned there are 165
some overloaded versions of a lot of overloaded versions. 166
This is taking an entire day but you also have or a double idea and so on. 167
Now there is also another version of SOC which takes a competitor. 168
Here we have general extradition which is fine. 169
We can you will understand later but it takes a competitor. 170
So earlier post natural ordering about this sort of notion sort method will take a competitor and uses 171
that competitor to sort the elements and the commandant out in here. 172
So you're done with sorting we are done with as list next is binary search on the binary search method 173
. 174
Basically it takes an hour day and will search for this. 175
It's a search method Mystikal your search matter under which it uses binary search algorithm. 176
So it is used for searching for this element. 177
The second parameter in this input. 178
OK on the return type is if the element is fun done the group returned the index of the element in the 179
Arctic. 180
Otherwise the binary search method then look at the index position where this element can be inserted 181
. 182
If the element is not then and it returns the insertion point and negates it and oxyd minus one. 183
And the specification also says that the input must be sorted. 184
Otherwise the behavior is undefined but does the specification but it all depends upon the JVM implementation 185
and on my mission. 186
Even if that is not sorted it still finds the element Anderton's the appropriate index even if it is 187
not shocking what can go ahead and look at this burn statement here. 188
So we have the Areff 4:23 and fifty nine and we are trying to search for this element for under childred 189
done the index 0 undertaken zero. 190
Now let's look for five under-achieved return. 191
I guess Heterodynes minus two minus two. 192
OK because you would have been inserted here at the first position. 193
And we are right in your minus one quick K minus off one and another minus one. 194
So that's about the binary search matter. 195
Now let's look at copy off. 196
So as a name names I'll just copy off what's included in a copy of this idea. 197
And we are also specifying the method. 198
OK. 199
We are also specifying the Nant of the new ID. 200
Now if that length is greater than the length of this input array then for all the remaining slots. 201
OK it would copy all of the elements from this from. 202
From this era into the new array. 203
But for all the remaining elements remaining slots it would add a zero. 204
So the new array will be written here. 205
So to me you know and so here is a new audit. 206
Now data size has been increased often you already are just filled with zero. 207
Next is this is a slight detour. 208
There is an audit copy mattered in the system class which is from the dollar dot like package on it 209
but almost the exact same thing. 210
So I just want to show that also I think we'll discuss this matter earlier involved that occurs. 211
So it takes this input it which is the source. 212
And this is their destination ID. 213
And this is the position in the source are they from where we want to start copying the elements. 214
And this is their destination. 215
And this is the start position in the data destination are they where we want to copy the elements from 216
IRA and Ira learned as the number of elements that need to be copied and if new or it happens to be 217
a larger area than all the all the slots of the remaining slots will be filled with zero. 218
This doesn't that all be all. 219
So let me just run that also. 220
He does search just the same array. 221
So these are two different areas. 222
In fact copy off actually in dentally uses a copy but probably does a slightly cleaner way to do it 223
because the the other you don't have to pass on our eight week new ID. 224
It in itself is creating order under disorder Dunning it. 225
So that's the added copy. 226
So that's how you do it instead of creating a for loop and rotating. 227
I needed to the follow up on creating a new ID and copying that immense friend. 228
You can use a single statement in this way. 229
Next as a film after the film that basically takes an ID and fills each element with this element. 230
So once you invoke this every element will have in the table have this 130. 231
So that's got you. 232
Or does the new array now has only 30 so that's a good way to initialize not a bet on the one element 233
. 234
Now next this equals my third equals but that basically takes both the address and would return true 235
if both the items are equal which means that dot is off the same type of the same size and they have 236
the exact same contents. 237
So let's just try that on your phones because Ira has these elements 4:23 19 but nobody has these elements 238
. 239
OK. 240
So it's not equal. 241
So that's the equals method. 242
Now finally let's look at these medical deep equals. 243
So it is also equals third but it does it beat equals which means that if we have mastered Aarhus then 244
it would still be able to compare the IDs. 245
No it's not just a single dimension but multi-dimensionally is going to start out is but this metric 246
takes an hour off object. 247
So here we can see that it's an array of objects to or else objects are just the comparison. 248
So if our eyes are deeply equal to one another and by deeply it means that there are more than what 249
are appropriate for nested M.S.. 250
OK so let's go ahead and look at a few examples here we have to be buddies. 251
They are a one on deep or two which are three dimensional arrays and these are the elements. 252
And in this print statement we are working with the artist you just run it and you agreed and said to 253
my wife I changed this to sixty one. 254
OK. 255
Now it does not equal under two fonts. 256
Knowledge is a two dimensional not a. 257
Here going the same elements and it will also work fine. 258
OK. 259
Now let's take the next example which is of one dimension. 260
Now with this we get a combine. 261
OK. 262
That's because all of these ideas cannot be assigned to idea of objects. 263
The reason is this whole thing is just an object. 264
It is not an idea of object if it was an object then it would have been fine. 265
Now here this is an odd off in art and art is an object so an art off and art is basically an idea or 266
object. 267
And so there was no problem. 268
But here it is just an object. 269
It's not an object. 270
So this they call it does covariance let go and variants as if there are two types. 271
Let's say one of them is object on the other one is an integer. 272
Now we know that indeed there is a subtype of object. 273
So if that is the case then it also means that object. 274
RFE RL object is a supertype of integer so if integer is it's a type of object then an integer is a 275
. 276
So pipe all idea off ogic. 277
So that's what covariance means. 278
OK. 279
And that does not work here as in but it is not as a type of object or object at it. 280
OK but had it been like this then it would be fine now. 281
So this does not compile. 282
OK so that's what's also that's an important thing. 283
And we'll get back with this covariance thing and generics lesson because in genetics with genetics 284
we have a property called invariants. 285
So when we get data we will once again discuss this covariance property off ice and here. 286
So here earlier it was a off object was a barometer of the quotes. 287
So we are just demonstrating something here. 288
So here we are trying to assign an three dimensional not so here this would be an idea or object right 289
. 290
So I guess it would be an idea off and in two dimensional I guess it could get stronger as a two dimensional 291
body not a three dimensional body on here. 292
And this equipment the value of zero of two it would be three. 293
So that's all it is just a monster. 294
The same thing we have these three statements. 295
Let me also show the API. 296
So as you can see each Metford like the binary search has all these different parameters. 297
There is also some arrangement there. 298
Here you can take a look at this. 299
So each degree of methods have several overloaded versions. 300
So that's the artist class and that's it. 301
And the court will be available in the resource section and that's about it. 302
Thank you and I'll be quoting