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