1

00:00:01,160  -->  00:00:03,220
OK let's not write them off on a list.

2

00:00:03,540  -->  00:00:09,090
So in the last lesson bilabiate brought another list is an buter looked at few methods from the list

3

00:00:09,090  -->  00:00:11,820
interface and also in this class.

4

00:00:11,820  -->  00:00:16,260
So in this demo we'll be looking at all of those methods and we You'll also look at a few methods from

5

00:00:16,260  -->  00:00:19,900
the collection interface which is the root interface.

6

00:00:19,950  -->  00:00:25,680
So for this demo I have created this new package called Comdex semantics credit collections and I have

7

00:00:25,680  -->  00:00:29,080
also created a new class within that package called list them all.

8

00:00:29,490  -->  00:00:34,440
And within the this demo class we have this method called us our deadliest demo which we are going to

9

00:00:34,560  -->  00:00:36,070
fill in this in this demo.

10

00:00:36,150  -->  00:00:40,920
So we are going to write some code here and it's a pirate's topic matter that is invoked from the main

11

00:00:40,920  -->  00:00:42,060
method.

12

00:00:42,300  -->  00:00:43,880
So we're going to write some code.

13

00:00:44,100  -->  00:00:47,420
And we also have some code that has already been written.

14

00:00:47,940  -->  00:00:50,810
So that is done in the interest of time.

15

00:00:50,840  -->  00:00:55,150
So when we get here we'll be just looking at the court and we'll just run the program.

16

00:00:55,500  -->  00:00:58,430
But before doing that we will write some code here.

17

00:00:58,440  -->  00:01:01,080
So let's go ahead and first let's create an idealist

18

00:01:01,080  -->  00:01:06,630
.

19

00:01:08,510  -->  00:01:08,880
OK.

20

00:01:08,880  -->  00:01:15,150
He had the name of the artlessness list one and here that referenced this collection which is an interface

21

00:01:15,690  -->  00:01:21,390
and we have created an Adela's OK so we should always try to program plan interface.

22

00:01:21,390  -->  00:01:25,640
We know that because if you do that we can easily change the implementation.

23

00:01:25,680  -->  00:01:32,110
So if we want to use linguist all we need to do is change this to a linked list and collection interface

24

00:01:32,110  -->  00:01:33,390
since it is the root interface.

25

00:01:33,420  -->  00:01:36,040
It gives us the maximum generality.

26

00:01:36,270  -->  00:01:38,250
And we know that these facts are related to generics.

27

00:01:38,250  -->  00:01:39,520
So let's not worry about it.

28

00:01:39,660  -->  00:01:45,300
But for now it would suffice to understand that since we have integer here in between the stocks it

29

00:01:45,300  -->  00:01:47,860
means that it's an other list of India.

30

00:01:48,090  -->  00:01:52,090
So this list this particular analyst can store only integers.

31

00:01:52,260  -->  00:01:57,780
So if we try to add any other object other than an integer then we get a compiler error.

32

00:01:57,780  -->  00:02:02,030
Now if you want to Ardelia's to store to store on these strings then we simply have to change just a

33

00:02:02,040  -->  00:02:02,900
string.

34

00:02:03,060  -->  00:02:05,830
And if it needs to be double we just change it to double.

35

00:02:06,400  -->  00:02:10,010
So in that sense it is genetic.

36

00:02:10,050  -->  00:02:16,280
So the idealist can store anything any any particular object and all we need to do is do this through

37

00:02:16,280  -->  00:02:20,390
of genetics notation we need to indicate the kind of objects that we want to store.

38

00:02:20,640  -->  00:02:23,240
And that's the reason why it is Carlist genetics.

39

00:02:23,430  -->  00:02:27,970
It makes our Clausius genetic to distort anything anything that we want.

40

00:02:28,290  -->  00:02:31,190
So that's about it for now with regard to genetics.

41

00:02:31,240  -->  00:02:33,310
And we will discuss it when we get there.

42

00:02:33,690  -->  00:02:34,790
But all that he does.

43

00:02:35,070  -->  00:02:39,210
So let's just go ahead and add few elements to do this or at least

44

00:02:45,660  -->  00:02:46,060
sort of.

45

00:02:46,090  -->  00:02:47,780
I do.

46

00:02:48,270  -->  00:02:50,420
Let's add a duplicate here.

47

00:02:50,810  -->  00:02:56,450
And let's And not since honorless can store both duplicates as well as null.

48

00:02:56,730  -->  00:02:59,880
Let's go ahead and print the elements.

49

00:02:59,890  -->  00:03:03,700
No the mirror on it.

50

00:03:04,500  -->  00:03:09,900
So as you can see they're distorting all these elements and it can store duplicate as well as other

51

00:03:09,900  -->  00:03:11,190
values.

52

00:03:11,190  -->  00:03:15,340
Now let's go ahead and remove the element at that third index.

53

00:03:15,360  -->  00:03:18,290
This is 0 1 2 and 3 it needs to remove this one.

54

00:03:18,300  -->  00:03:27,570
So let's go ahead and say at least one board read more.

55

00:03:27,570  -->  00:03:31,030
So that element or that third position has been removed.

56

00:03:31,390  -->  00:03:35,510
Now the set list.

57

00:03:35,760  -->  00:03:37,520
So let's do this one more time.

58

00:03:37,590  -->  00:03:47,760
In that case it has to remove the value knowledge since it is at the third position in 0 1 2 and 3.

59

00:03:47,910  -->  00:03:53,820
Now as you can see it did not remove nutten but it removed the elementary.

60

00:03:53,820  -->  00:03:58,880
So the reason for that is because it is due to metal binding.

61

00:03:58,950  -->  00:04:04,620
If you recall our lesson on method binding we said that there is this method signature binding which

62

00:04:04,620  -->  00:04:06,990
happens at compile time itself.

63

00:04:06,990  -->  00:04:12,900
So at compile time the compiler is looking at the reference type which is collection in this case and

64

00:04:12,900  -->  00:04:17,200
collection has this method called remote island.

65

00:04:17,250  -->  00:04:19,140
It has this parameter object.

66

00:04:19,140  -->  00:04:27,210
So at compile time the compiler will try to find an exact match a method with which has the exact parameter

67

00:04:27,210  -->  00:04:28,760
which is an NPR remote off.

68

00:04:28,770  -->  00:04:32,570
And but the collection interface does not have that method.

69

00:04:32,700  -->  00:04:37,010
The removal of a method is present only in the list interface.

70

00:04:37,170  -->  00:04:39,130
Ok but not in the collection interface.

71

00:04:39,480  -->  00:04:45,870
But then compiler sees that it did not find the exact match and method with the exact matching signature

72

00:04:45,900  -->  00:04:49,470
but it found a method having compatible signature.

73

00:04:49,630  -->  00:04:55,770
OK so in that case in the bike code it's going to write that the method that needs to be invoked should

74

00:04:55,770  -->  00:04:56,840
have the signature.

75

00:04:56,970  -->  00:04:58,860
OK I don't mind the JVM.

76

00:04:58,860  -->  00:05:06,420
Well really try to find the most specific method having the signature which is also present in the list

77

00:05:06,450  -->  00:05:08,880
interface in other districts.

78

00:05:09,450  -->  00:05:15,900
So if you don't recall just go back to the coalescent on method binding and you can under the topic

79

00:05:15,900  -->  00:05:18,600
on the method signature binding will explain this.

80

00:05:18,600  -->  00:05:19,130
So.

81

00:05:19,130  -->  00:05:19,890
So that's about it.

82

00:05:19,890  -->  00:05:21,400
So that's the reason why.

83

00:05:21,660  -->  00:05:27,570
So actually even when we invoke up here in the first instance it was not removing the element of purpose

84

00:05:27,700  -->  00:05:27,900
.

85

00:05:27,930  -->  00:05:30,960
But it was actually removing the element 3 itself.

86

00:05:30,990  -->  00:05:31,740
OK.

87

00:05:31,860  -->  00:05:35,220
And the same happened here it remove are the elementary.

88

00:05:35,220  -->  00:05:42,600
Now if you want to make make it are the element at the Toti next door be removed then we need to change

89

00:05:42,600  -->  00:05:44,090
this list.

90

00:05:44,130  -->  00:05:50,480
In fact let's change it to list and that's because the the methods that we are going to invoke math

91

00:05:50,500  -->  00:05:50,580
.

92

00:05:50,640  -->  00:05:56,250
Next we are going to write next are specific to our position specific methods.

93

00:05:56,430  -->  00:06:02,740
So we each have an index number as the parameter on disposition specific methods are specified only

94

00:06:02,750  -->  00:06:04,550
and the list interface.

95

00:06:04,800  -->  00:06:10,890
Now if I run this you can see the non-God to look at which means that it didn't work the method.

96

00:06:11,370  -->  00:06:13,720
This particular mother more off and.

97

00:06:13,920  -->  00:06:14,710
OK.

98

00:06:14,910  -->  00:06:21,780
So that's that's the metric signature of a lot of people in order to understand that how them at their

99

00:06:21,780  -->  00:06:23,440
signature binding works.

100

00:06:23,490  -->  00:06:29,250
So you can go back and refer to that particular lecture and object oriented programming.

101

00:06:29,250  -->  00:06:34,730
Now let's go ahead and write some positions specific methods.

102

00:06:36,660  -->  00:06:40,820
Let's add an element at zero.

103

00:06:42,780  -->  00:06:45,450
So you have a new element here added at zero.

104

00:06:45,600  -->  00:06:46,680
It's.

105

00:06:46,800  -->  00:06:51,060
So that's the I'd mutter that an index here is zero.

106

00:06:51,060  -->  00:06:55,960
Now let's try the set matter.

107

00:06:56,490  -->  00:07:03,690
So let's set the element of zero position with just 10 to nine.

108

00:07:03,700  -->  00:07:10,230
There you go so nine has been added and this method would return the previous elements stored at that

109

00:07:10,230  -->  00:07:12,010
position which would be then.

110

00:07:12,030  -->  00:07:16,280
OK so these are the new elements that we have 9 1 2 and 3.

111

00:07:16,350  -->  00:07:18,940
So those are the items segment.

112

00:07:19,090  -->  00:07:21,790
Now let's look at some bulk operations.

113

00:07:21,900  -->  00:07:25,060
So we know that the collection interface are some bulk methods.

114

00:07:25,200  -->  00:07:26,670
So here it is.

115

00:07:26,670  -->  00:07:27,900
So let me uncomment this.

116

00:07:27,930  -->  00:07:29,280
So it's already there.

117

00:07:29,280  -->  00:07:31,300
So here we are creating a new list.

118

00:07:31,500  -->  00:07:31,800
OK.

119

00:07:31,810  -->  00:07:32,610
In New Collection.

120

00:07:32,610  -->  00:07:39,580
It's called us let's do I've got two elements 9 and three iron from list 1.

121

00:07:39,660  -->  00:07:45,760
We are woking we are invoking the remove all method on list 1 and we are passing listed as the input

122

00:07:45,810  -->  00:07:47,710
barometer input argument.

123

00:07:47,760  -->  00:07:51,330
So we want to remote If list one has both these elements.

124

00:07:51,330  -->  00:07:53,800
We want to remove them from list 1.

125

00:07:54,450  -->  00:07:57,750
So let me just run this.

126

00:07:58,240  -->  00:08:01,960
So we only lost 100 only 9 1 2 and 3.

127

00:08:02,160  -->  00:08:03,770
So list 2 had 9 and 3.

128

00:08:03,780  -->  00:08:05,620
So we have removed the bench.

129

00:08:05,700  -->  00:08:07,840
So we are left with only one and 2.

130

00:08:08,220  -->  00:08:09,500
Now go let's go.

131

00:08:09,600  -->  00:08:11,800
Iron I have one Boulis too.

132

00:08:11,820  -->  00:08:14,390
So let's to had already had nine and three.

133

00:08:14,400  -->  00:08:17,890
Let's also add one to it and let's.

134

00:08:17,970  -->  00:08:19,490
In order to retain All-Met there.

135

00:08:19,530  -->  00:08:23,370
So we'll have more on NEXT is reading all matter.

136

00:08:23,400  -->  00:08:25,030
Here it is written on.

137

00:08:25,380  -->  00:08:26,270
So read in.

138

00:08:26,270  -->  00:08:32,310
All well written all the elements present and list do on that word remove all the remaining elements

139

00:08:32,330  -->  00:08:32,480
.

140

00:08:32,640  -->  00:08:41,330
OK so list one right now has only 1 1 and 2 and a list to list one has one undo unless Drew has a 93

141

00:08:41,340  -->  00:08:42,220
on one.

142

00:08:42,330  -->  00:08:44,060
So the only common element is 1.

143

00:08:44,190  -->  00:08:47,700
So it will retain that and really move to.

144

00:08:47,820  -->  00:08:48,670
Here it is.

145

00:08:48,720  -->  00:08:53,570
So it retained one deleted element.

146

00:08:54,300  -->  00:08:56,340
So we are done with the remote all undereating on.

147

00:08:56,340  -->  00:08:58,220
Let's look at at all.

148

00:08:58,290  -->  00:09:01,330
So let's just go ahead and simply add the elements off list to do list 1

149

00:09:04,560  -->  00:09:12,100
because you can see the three elements mind three and one which were part of list 2 are ordered to list

150

00:09:12,170  -->  00:09:12,900
1.

151

00:09:12,930  -->  00:09:15,160
So that's the ideal method.

152

00:09:15,240  -->  00:09:18,270
And let's also do this.

153

00:09:18,300  -->  00:09:21,080
So this is just pure setting the value.

154

00:09:21,180  -->  00:09:28,810
Enlist one element at indexable they do is reset to two which means that this tree gets changed to sort

155

00:09:28,810  -->  00:09:31,620
of try on it once again.

156

00:09:31,620  -->  00:09:34,350
And here it is here.

157

00:09:34,390  -->  00:09:41,160
The set met there simply returns the search the value at that particular index to do under the previous

158

00:09:41,160  -->  00:09:44,190
element the previous element of the next Wall Street.

159

00:09:44,190  -->  00:09:45,340
So it's district running back.

160

00:09:45,360  -->  00:09:47,360
So you're just printing out that value.

161

00:09:47,730  -->  00:09:49,140
So those are the bulk operations.

162

00:09:49,170  -->  00:09:51,200
And this was just a set operation.

163

00:09:51,240  -->  00:09:54,540
Now let's go ahead and look at some such methods.

164

00:09:54,630  -->  00:10:01,220
Here we are so the first one as the contains mentored and we are just checking if the element one is

165

00:10:01,220  -->  00:10:08,930
present and the last one second is index off which gives the first utterance of the element of the next

166

00:10:08,930  -->  00:10:12,710
number of the first occurrence of this particular element if it is present.

167

00:10:12,770  -->  00:10:18,350
If not it would read and a minus one third one is lost and next off which would give the last index

168

00:10:18,350  -->  00:10:21,090
off the goodness of this element.

169

00:10:21,140  -->  00:10:23,010
So let's run this.

170

00:10:23,500  -->  00:10:29,520
Now as you can see the element 1 is present and the last one and the last one.

171

00:10:29,570  -->  00:10:32,960
So it returns a true here on the index position.

172

00:10:32,960  -->  00:10:34,630
When we do index off it is zero.

173

00:10:34,640  -->  00:10:41,160
But when we do the last index off it gives three because the last element here is one.

174

00:10:41,210  -->  00:10:41,450
OK.

175

00:10:41,450  -->  00:10:44,220
So it gives up in next three.

176

00:10:44,240  -->  00:10:45,980
So those are the search operations.

177

00:10:45,980  -->  00:10:49,470
Now we also discussed a broader range view the sublist method.

178

00:10:49,820  -->  00:10:51,890
So let's also try that.

179

00:10:53,030  -->  00:10:56,700
So range rules just because that's part of the list interface listen.

180

00:10:56,870  -->  00:11:06,890
So here we are calling the sublist matter and we are saying we are asking for a sublist and the element

181

00:11:07,220  -->  00:11:13,120
indexes are the lets us do the two indexes three so it will return only one element Element 2.

182

00:11:13,120  -->  00:11:14,590
Because this is exclusive.

183

00:11:14,870  -->  00:11:18,450
So the the name of this list is list 3.

184

00:11:18,450  -->  00:11:20,420
That's the sublist.

185

00:11:20,450  -->  00:11:23,440
We said that the list 3 when we do a sublist.

186

00:11:23,480  -->  00:11:29,200
This particular list is backed up by the origin of that original idlest which is a list 1.

187

00:11:29,380  -->  00:11:34,760
So which means that any changes that we make to this new list will be reflected in that list.

188

00:11:35,330  -->  00:11:38,920
So let's go ahead and run this.

189

00:11:39,230  -->  00:11:40,460
Here it is.

190

00:11:41,090  -->  00:11:50,270
So in the list 3 Initially it had only it had only the element at index position to know we are setting

191

00:11:50,270  -->  00:11:54,020
it to 6 and we are printing list one here.

192

00:11:54,050  -->  00:12:01,100
So as you can see when we have said the value industry it also got to reflect it and list one on that

193

00:12:01,100  -->  00:12:05,850
particular value at position you got updated.

194

00:12:05,930  -->  00:12:06,490
OK.

195

00:12:06,860  -->  00:12:09,860
Now we are updating the value we are.

196

00:12:09,860  -->  00:12:13,030
I think a value to list three.

197

00:12:13,270  -->  00:12:17,010
Now when we do that it also gets reflected in list 1.

198

00:12:17,180  -->  00:12:18,270
So we're adding it.

199

00:12:18,380  -->  00:12:24,770
The position zero but that position zero is actually the index position to and list one.

200

00:12:24,770  -->  00:12:30,890
So as you can see the elements 7 what I did on the other two elements got shifted to right.

201

00:12:31,120  -->  00:12:37,250
So any change that you'll make in this new list will be reflected in that and that put you in the back

202

00:12:37,500  -->  00:12:41,890
of a list which is the original list which just listed them.

203

00:12:41,990  -->  00:12:45,350
So we have made some changes in the new order list in the sublist.

204

00:12:45,350  -->  00:12:46,890
And that got reflected here.

205

00:12:46,930  -->  00:12:53,540
No need to make some change in the original list and see that it gets reflected in the industry.

206

00:12:53,570  -->  00:12:55,560
So here we are making a change.

207

00:12:55,630  -->  00:13:03,350
We are setting we are resetting the value of the element at position to 8 under to see if it gets reflected

208

00:13:03,350  -->  00:13:05,370
in industry.

209

00:13:05,420  -->  00:13:06,980
So we are printing a history here.

210

00:13:06,980  -->  00:13:13,630
And as you can see the history the value at zero at the position index 0 got changed to 8.

211

00:13:13,850  -->  00:13:18,520
So the change was made in this one and it got reflected in history.

212

00:13:18,770  -->  00:13:27,260
Now let's see if we can I add an element and last one on whether it gets reflected in industry.

213

00:13:27,770  -->  00:13:36,120
So we're adding an element at index position zero in the last one and it doesn't.

214

00:13:36,130  -->  00:13:40,120
So we are we have we just tried to add an element and to list one.

215

00:13:40,340  -->  00:13:46,260
But when we tried to prend the elements of history it did not look.

216

00:13:46,490  -->  00:13:51,200
So we can only make non-structural changes in a just one.

217

00:13:51,230  -->  00:13:54,700
Only then we can access the elements in history.

218

00:13:54,710  -->  00:13:59,360
Now let's say we made a structural change here a structural changes adding an element or deleting an

219

00:13:59,360  -->  00:14:06,260
element and when we do that then if we try to do when we try to access any of them at industry then

220

00:14:06,260  -->  00:14:09,950
we get an exception under System and modification exception.

221

00:14:09,950  -->  00:14:18,140
So anything we can do as analyst one we can or we can set something in that case it is fine but if we

222

00:14:18,130  -->  00:14:24,100
make any structural change in the back array then the new order the sublist will throw an exception

223

00:14:24,110  -->  00:14:26,610
when we try to access any of its methods.

224

00:14:27,320  -->  00:14:28,790
So that's the thing.

225

00:14:29,210  -->  00:14:33,140
But if we make any changes in the in the sublist then it is fine.

226

00:14:33,140  -->  00:14:36,050
We can I'd also be we can make structural changes.

227

00:14:36,050  -->  00:14:39,830
Also industry then that gets reflected in last one.

228

00:14:40,020  -->  00:14:40,690
Okay.

229

00:14:40,900  -->  00:14:42,730
So that's the thing.

230

00:14:42,730  -->  00:14:46,030
Now let me uncommon this.

231

00:14:46,120  -->  00:14:52,010
I think we are just printing the same elements not as it it through the elements of the of the list

232

00:14:52,010  -->  00:14:52,180
.

233

00:14:52,190  -->  00:14:57,340
So we are simply having a For Each loop here.

234

00:14:59,300  -->  00:15:02,740
But let me just Carmen this note.

235

00:15:03,130  -->  00:15:04,590
My read on it.

236

00:15:05,270  -->  00:15:10,560
So as you can see we are just iterating through the elements and I'm just printing all these five elements

237

00:15:10,610  -->  00:15:12,280
and the last one.

238

00:15:12,320  -->  00:15:14,660
Now let's see if element is nine.

239

00:15:14,690  -->  00:15:17,520
So the 11 element minus here the second element.

240

00:15:17,670  -->  00:15:22,270
Let's say we want to remove that element from the last one.

241

00:15:22,280  -->  00:15:22,720
OK.

242

00:15:22,790  -->  00:15:24,480
So we are iterating through last one.

243

00:15:24,740  -->  00:15:30,440
But if the element current element happens to be 9 we want to read more and see what happens.

244

00:15:30,950  -->  00:15:32,940
As you can see we get an exception here.

245

00:15:33,020  -->  00:15:35,370
It's a concussion modification exception.

246

00:15:35,730  -->  00:15:40,420
So and So that element 1 got printed here here and then element 9.

247

00:15:40,430  -->  00:15:41,720
The second element was 9.

248

00:15:41,750  -->  00:15:47,570
It also got printed but if element is nine we are trying to remove it and then it throws in concurrent

249

00:15:47,570  -->  00:15:49,400
modification exception.

250

00:15:49,390  -->  00:15:54,920
So the thing is when we are iterating if we want to remove a particular element during the iteration

251

00:15:55,550  -->  00:15:57,920
then we cannot do it using a for each statement.

252

00:15:58,040  -->  00:16:03,320
And for that we need to use it for that matter which is the subject of next lesson.

253

00:16:03,400  -->  00:16:03,980
OK.

254

00:16:03,980  -->  00:16:04,800
Using an editor to.

255

00:16:04,810  -->  00:16:05,970
We can do that.

256

00:16:06,050  -->  00:16:08,550
And so that we will see in the next lesson.

257

00:16:08,650  -->  00:16:09,310
So thank you.

258

00:16:09,320  -->  00:16:13,400
And this code is available in the resources section for download and you can download our and you can

259

00:16:13,390  -->  00:16:15,150
run it on happy coding.

260

00:16:15,140  -->  00:16:16,450
And thank you.
