Hi there. 2
So in the last lesson we looked at our response which was use for money plodding R.S. understrapper 3
. 4
We looked at several different data structures on Vinita class to mount a ghosty does not just right 5
on for that we have this class called us collection's which is also from the Jellico jungle package 6
. 7
So we know that there is that collection interface which is singular and this one is brutal. 8
And this glass is also very similar to the artist's glass. 9
So it is a utility glass with lots of static methods on it helps us in doing stuff like soft things 10
searching on there are also some other exotic methods which we are going to see and many of them at 11
that's how excessive genetics notations. 12
OK. 13
So just don't worry about them. 14
I need to be clear when we get there. 15
So here in this demo how created this class called us collections them all under it is added to the 16
collections package and everything will be demonstrated in the main method. 17
So we'll be writing some code on some of the core in the interest of time has already been there done 18
so with this doc. 19
So the first method that I would like to demonstrate is idle. 20
OK. 21
And that takes two parameters. 22
One is a collection and others. 23
And Ari on all it does this I are in the means to that collection. 24
OK. 25
Undergirds a boolean flag. 26
So here we are creating an instance of idlest and we are adding three elements. 27
Raj John on one more John and we are also creating this are they OK. 28
Honored has only one element on. 29
So let's go ahead and enrich our alma mater. 30
So let's just say I don't see a passing list on the second one is Ari managed to spend less now says 31
UG on Goldsby is so much stronger. 32
And you can see all the elements right. 33
John and John on Anita has been added to the list. 34
OK. 35
Now you may recall this from our collection the is that there is a method called eye on right now that 36
are all very big a collection it are a collection of this collection. 37
OK. 38
So that is for adding a collection to another collection and if you want to budak we can make use off 39
of it is not as old as you have seen that in the last lesson and we have to just pass the RV right. 40
So that can also be done. 41
But this is likely to be faster than this approach. 42
OK. 43
So just keep that in mind. 44
So that's the out on the matter. 45
Our Next let's look at the Salk method. 46
So we have looked at the Salk method in Addis. 47
So it just looks identical. 48
So this would just sort the elements. 49
So in this case the parameter is just in last. 50
OK. 51
It's going to Sadako on this particular sock method they will use natural ordering which means that 52
elements of the list must implement built into office. 53
So let's just go ahead and simply invoke the sock method 54
and that's all there is to it. 55
So I didn't know. 56
OK. 57
And there is also another version which will take a competitor as an input in addition to the list in 58
which I guess it would use the comparative foreshortening. 59
OK. 60
You can take a look at the Kodak. 61
So that's the sorting method. 62
Next let's look at binary search. 63
Now if you recall binary search was also there not as glass. 64
So it is also here and not connections. 65
OK. 66
And this is the definition of it. 67
So binary search matter is making a collection and list here. 68
And it is searching for the key. 69
OK. 70
Now one thing I want to tell about the saut is as you can see it is only for a list but it's not making 71
any sense. 72
The reason for that is if you want a softer search you can actually use tricyclics and. 73
OK so there is a reset so you can just make use of die. 74
Now for Hasek said you cannot solve the elements if at all if you want to solve the elements of Hasek 75
which I think you might never want to do. 76
But if you want to do it. 77
So there are two approaches. 78
One is you can create a preset instance of instance on in the constructor one of the constructors accepts 79
and collection so you can just pass a Hosack or you can create an idealist on bass and use one of the 80
constructors which make a collection on pass Half-Chick and then you can invoke this method. 81
So OK so sauteeing is only for it. 82
And this particular in this particular class now come into a binary search site will be used for searching 83
for a key in the event last year and the requirement is that it needs to be soccer and if it is it then 84
it would be love. 85
To me the convexity would be longer to make read and is the size of the list. 86
Now you may recall that the list also has a called on base and that is linear. 87
The complexity is linear. 88
So this one is better than that. 89
Hello are here the elements that require us. 90
Each element has to be has to implement comparable indices. 91
That's what this binary search method requires now. 92
So the requirement is that the list and amounts have to be sorted. 93
Now if it does not Sautter then the specification says that behavior of this method is undefined. 94
OK so it might perform a search on it might return the index value so that I recall that it returns 95
the index if the element is found on. 96
It might return the value that it might find the element on it might return an index value even though 97
the even though it's not charted but the it will not be a binary search so it might just do a regular 98
linear search. 99
But if binary search has to be pulled from then it must remain. 100
Must be soccer. 101
Once again it takes only a list I'm not a set because how set is already really efficient it is. 102
It has constant time on plexis before searching for an intermediate. 103
Similarly research is also very efficient. 104
It is my job to make. 105
So it is on just similar to a binary search. 106
So that's the reason they did not provide another matter just for sex. 107
The regular set classes do not die. 108
OK they're very fast for such a right set implementations. 109
Regarding uniqueness and also fast lookups There is also a binary search matter for which Dick's competitor 110
. 111
OK so it picks a competitor to search for a D in the list of elements and uses the competitor to find 112
out. 113
OK so you can also read got from the API. 114
So let's just go ahead and search for something that you didn't see says on gold space. 115
Let's search for Mr John. 116
Is John there. 117
So this should done one. 118
And so on here. 119
Right. 120
So that is because John is at an expedition 1 OK so surgery and so fast. 121
An explosion. 122
So that's about the search. 123
Now there are a bunch of matters that are very straightforward. 124
So let's just go ahead and look at what they do. 125
And you should be very straightforward. 126
Just common this. 127
Ugh. 128
OK so let's just go ahead and look at each of them at us. 129
So the first one is the worst as you may expect it will just leave the elements in the list. 130
OK what was the list. 131
Next this VOP method. 132
It basically swaps two elements. 133
It's index and swaps them under is and method call frequency. 134
It just looks for this particular element and tells us how many times it appears in the list. 135
Next the shuffle exhibition closes the list. 136
So let's just go ahead and run them on we can discuss the book. 137
Here it is first the reverse list. 138
So this was the list on a thought John. 139
John onrush. 140
So this is the reverse list Saroj. 141
John John and Anita Kay. 142
All we are doing is invoking the article we were smattered on passing list. 143
Next is the worst. 144
Also written and so quiet so just keep that in mind it's just going to work on this list. 145
Next to a swap matter. 146
We are into changing the elements of zero on 3 so 0 is Rotch and 3 is unequal. 147
So as you can see here that Adman's got swapped. 148
Or maybe this list next is a frequency we are searching for John and John is appearing twice. 149
So just bending to next with a shuffle shuffle us and shuffling shuffling got. 150
OK if you run it one more time you may see a different order. 151
There you go. 152
Soit is mainly useful. 153
One instance where it can be used for example if you are implementing some kind of a card game. 154
If you want to shuffle the cards you can make use of this. 155
OK but parts will be inside the list or if you are holed up in some kind of a site. 156
If your home page displays a list of items so the list of items can be there for the entire day. 157
I know for each Oxus if the user is performing that is refreshing the home page. 158
You might want to just shuffle the list and show it to the user that made the list looks more are refreshed 159
and start off being stale so that you can you can make use of shuffling. 160
OK now so does the shuffling list on this Mock's one really just shouldn't go Max. 161
Element excessive or the maximum element of the given collection. 162
So does returning the max element. 163
And for that it makes use of the natural ordering off its elements. 164
So if you look at the natural order in here Raj is the Max. 165
Max enemy. 166
Anita is the middle of me so it makes use of Doc max and min and so Dodo's max and min. 167
So next let's look at this method called less Singleton not a singleton method it takes an element undertones 168
and set on the central how this particular element is really how any one element on the set is immutable 169
. 170
Which means that you cannot add any elements to it. 171
And this is one good idea. 172
We know that there is more on matter when you take a collection and really try to remove the elements 173
in the collection from the current action. 174
Not that's all it does. 175
I mean if you want to if you want the collection in book collection to have only a single element then 176
you can make use of this kind of method. 177
This idiom can be used for that. 178
Otherwise you will have to create a collection externally. 179
Then our Jaun then Pasdar which looks a bit unclean. 180
So this is a more elegant way to do it. 181
And then there are also other methods like Singleton lists which were written in just hundreds of Singleton 182
map also which takes a key value pair of regions and map which has a single mocking. 183
OK so that's the singleton class. 184
Our next looks you'll get this method called less on modifiable collection. 185
OK. 186
So let's look at an modifiable collection. 187
So let's just say 188
it's just an modifiable. 189
OK. 190
Now this matter basically as the name suggests it returns send an modifiable view of the book collection 191
which means that it returns a collection. 192
But that particular connection is not modifiable. 193
OK. 194
You can not add any elements to it. 195
OK. 196
You can even modify it. 197
So it would be useful if you want to provide your client next to you or is an API. 198
Your clients are accessing your methods. 199
And if you want to provide only read access and you are in denial collections so you might be using 200
some collections within your core implementation. 201
But if you want to provide on the read only access then you can make use of this method. 202
And with that they can only read the elements of your collection but there will never be able to modify 203
the collection. 204
So let's just go ahead and actually try this or let's just print this once. 205
OK so if you want to search for something say 206
so you want to search for Annita 207
on it it's true. 208
OK. 209
So here in this case when the executor remore on John Mustoe got deleted. 210
So let's just go ahead and actually add John and it should give us an error because this is an modifiable 211
. 212
So let's do this. 213
OK so John is not there but we are trying to get him and we try to do this sort whosay unsupported operation 214
exception. 215
So you can never do it but you can do something like this. 216
This can be possible. 217
You can add something to the list here and then the element will get added to the on modifiable collection 218
return collection. 219
And as you say 220
if I copy this suit to you on it now you can see that John has been on it. 221
It's just that using this particular reference you cannot add anything normally to your clients. 222
You would just do it under this reference. 223
OK so this is not accessible anyhow. 224
So but this is just for your information. 225
So far all that debate is implemented is it uses a technical composition and forwarding. 226
We may discuss it later in a separate item in a separate lesson. 227
But the way it works is for all the read operations it will just delegate the control to the internalness 228
but for all other operations it will run unsupported operation exception. 229
Next issue could the court will hear this and this is creating an instance of an modifiable collection 230
and if you look at a modifiable collection you can see that all of these are real operations. 231
And if you invoke them it is actually invoking the the enclosed Amato's the the metal from the end glose 232
Plus which is which is the input parameter. 233
OK so that is just simply forwarding. 234
If you can more easily it's going to invoke the easy method and of the input. 235
OK so I'm just quoting the control bark for other methods. 236
Like if you want to do it during that duration if you are calling monitor echoes the unsupported operation 237
exception OK. 238
Even for our clothes on supported operation exception. 239
So that's called us imposition on forwarding. 240
I need to just the decorator pattern on later where we will most likely discuss an item from Africa 241
to Java where they will get back to this particular class. 242
And that's about it. 243
So just go ahead and look at the API iron when you're looking at the API. 244
You may see some methods that start with the key but empty like empty list on those matters will be 245
discussed in a subsequent lesson where we will be discussing an item from Effective Java undoctored 246
. 247
But very briefly not super important but I will be discussing that on other than that you may also find 248
some moderates which started the T-Bird check. 249
I'm going probably about them after we are done with generics. 250
You may come back and look at those methods on that because they related to generics by that related 251
to type safety. 252
But once again I don't think those are that important maintenance. 253
Finally there are some methods synchronized methods which start with a key and organized on those very 254
well. 255
And if you look on the chapter that's about it. 256
Thank you. 257
And you can find a code in the resource section. 258
Happy coding