7- The List Interface
Jun 21, 2026 09:43
· 3:51
· English
· Whisper Turbo
· 2 Locutores
Haec pagina de translatio explicat.
Despectus in Viam Permanentem →
Videtur solum
0:03
S…
Speaker 2 (7- The List Interface)
The list interface represents an ordered collection,
0:06
S…
Speaker 2 (7- The List Interface)
also called a sequence.
0:07
S…
Speaker 2 (7- The List Interface)
So with lists,
0:09
S…
Speaker 2 (7- The List Interface)
we can access objects by their index.
0:11
S…
Speaker 2 (7- The List Interface)
In collections,
0:12
S…
Speaker 2 (7- The List Interface)
we don't care about the index of objects.
0:14
S…
Speaker 2 (7- The List Interface)
We just care about adding or removing them from a collection.
0:17
S…
Speaker 2 (7- The List Interface)
So in your applications,
0:19
S…
Speaker 2 (7- The List Interface)
if you want to work with an ordered collection,
0:21
S…
Speaker 2 (7- The List Interface)
if you care about the index of objects in a collection,
0:24
S…
Speaker 2 (7- The List Interface)
you should use the list interface.
0:26
S…
Speaker 2 (7- The List Interface)
So let's declare a variable of type list of
0:30
S…
Speaker 1 (7- The List Interface)
string.
0:31
S…
Speaker 2 (7- The List Interface)
we're going to import this,
0:32
S…
Speaker 2 (7- The List Interface)
and set it to a new array list.
0:35
S…
Speaker 2 (7- The List Interface)
Now because the list interface extends the collection interface,
0:39
S…
Speaker 2 (7- The List Interface)
here we have all the methods you learned about in the last video.
0:43
S…
Speaker 1 (7- The List Interface)
So we can call list .add to add a few items,
0:47
S…
Speaker 1 (7- The List Interface)
A,
0:48
S…
Speaker 2 (7- The List Interface)
B, and C,
0:49
S…
Speaker 2 (7- The List Interface)
but we also have an overload of the add that takes
0:53
S…
Speaker 2 (7- The List Interface)
an integer.
0:54
S…
Speaker 2 (7- The List Interface)
So if you want to insert a value or an object at a particular index,
0:58
S…
Speaker 2 (7- The List Interface)
we use this overload.
0:59
S…
Speaker 2 (7- The List Interface)
Let's say I want to add
1:01
S…
Speaker 2 (7- The List Interface)
an exclamation mark at the beginning.
1:04
S…
Speaker 2 (7- The List Interface)
So you pass 0 as the index of the first item.
1:07
S…
Speaker 2 (7- The List Interface)
Now we can print the list and here's
1:13
S…
Speaker 1 (7- The List Interface)
the result.
1:13
S…
Speaker 2 (7- The List Interface)
We couldn't do this with the collection interface because collections don't support indexing.
1:18
S…
Speaker 2 (7- The List Interface)
Now we can also add multiple items in one go.
1:22
S…
Speaker 2 (7- The List Interface)
So here we call collections that
1:26
S…
Speaker 1 (7- The List Interface)
add all.
1:27
S…
Speaker 1 (7- The List Interface)
Now look at the first parameter.
1:29
S…
Speaker 1 (7- The List Interface)
It's a collection.
1:30
S…
Speaker 2 (7- The List Interface)
So because every list is a collection
1:33
S…
Speaker 2 (7- The List Interface)
Here we can pass our list object along with a few values
1:37
S…
Speaker 2 (7- The List Interface)
like a,
1:38
S…
Speaker 2 (7- The List Interface)
b, and c.
1:39
S…
Speaker 2 (7- The List Interface)
Here we can get an object by its index using
1:44
S…
Speaker 2 (7- The List Interface)
the get method.
1:44
S…
Speaker 1 (7- The List Interface)
So we can get the first item and print it and we get a.
1:49
S…
Speaker 2 (7- The List Interface)
We also have a method for replacing an object at the given index.
1:53
S…
Speaker 2 (7- The List Interface)
So list .set.
1:54
S…
Speaker 2 (7- The List Interface)
Let's set the first object to a plus.
1:59
S…
Speaker 2 (7- The List Interface)
Now we print the entire list and here's
2:05
S…
Speaker 1 (7- The List Interface)
the result.
2:06
S…
Speaker 2 (7- The List Interface)
We can also remove an object by its index.
2:08
S…
Speaker 2 (7- The List Interface)
Here we call list .remove 0.
2:12
S…
Speaker 2 (7- The List Interface)
Again,
2:13
S…
Speaker 2 (7- The List Interface)
we didn't have this method in the collection interface because collections don't support indexing.
2:17
S…
Speaker 1 (7- The List Interface)
Now take a look.
2:19
S…
Speaker 1 (7- The List Interface)
A is gone and we only have B and C.
2:22
S…
Speaker 2 (7- The List Interface)
Another useful method is the
2:27
S…
Speaker 2 (7- The List Interface)
index of method.
2:28
S…
Speaker 2 (7- The List Interface)
So we can call the index of method and pass A and
2:32
S…
Speaker 2 (7- The List Interface)
this will return the index of the first occurrence of A.
2:35
S…
Speaker 2 (7- The List Interface)
In this case,
2:37
S…
Speaker 2 (7- The List Interface)
it's going to be 0.
2:39
S…
Speaker 2 (7- The List Interface)
Now, if you search for a value or an object that doesn't exist here,
2:43
S…
Speaker 2 (7- The List Interface)
you're going to get negative 1.
2:45
S…
Speaker 1 (7- The List Interface)
There you go.
2:47
S…
Speaker 2 (7- The List Interface)
Another useful method is last
2:51
S…
Speaker 2 (7- The List Interface)
index of,
2:52
S…
Speaker 2 (7- The List Interface)
and this will return the index of the last occurrence of this object.
2:56
S…
Speaker 2 (7- The List Interface)
So if you add another a here,
2:58
S…
Speaker 1 (7- The List Interface)
the index of the second a is going to be 3.
3:02
S…
Speaker 1 (7- The List Interface)
So,
3:03
S…
Speaker 1 (7- The List Interface)
there you go.
3:06
S…
Speaker 1 (7- The List Interface)
Now I'm going to remove this.
3:10
S…
Speaker 2 (7- The List Interface)
Another useful method is the sublist method.
3:13
S…
Speaker 2 (7- The List Interface)
So we can call list .sublist.
3:17
S…
Speaker 2 (7- The List Interface)
Here we pass two indexes,
3:19
S…
Speaker 2 (7- The List Interface)
from and to.
3:20
S…
Speaker 2 (7- The List Interface)
From is inclusive,
3:22
S…
Speaker 2 (7- The List Interface)
but to is exclusive.
3:23
S…
Speaker 2 (7- The List Interface)
So we can start from index 0 and get all the items up
3:28
S…
Speaker 2 (7- The List Interface)
to index 2.
3:28
S…
Speaker 2 (7- The List Interface)
And this will return the objects at index 0 and
3:32
S…
Speaker 2 (7- The List Interface)
1. Take a look.
3:36
S…
Speaker 1 (7- The List Interface)
There you go.
3:36
S…
Speaker 2 (7- The List Interface)
Just realize that the original list is not affected because this
3:40
S…
Speaker 2 (7- The List Interface)
method returns a new list,
3:42
S…
Speaker 1 (7- The List Interface)
okay?
3:43
S…
Speaker 1 (7- The List Interface)
So this is all about the list interface.
3:46
S…
Speaker 2 (7- The List Interface)
Next we're going to talk about sorting data.
Haec transcriptio a AI (recognitione automatica loci) generata est. Errores continere potest - contra audio originalem verificare ut criticum utentur. Politicae
Summa
Haec pagina de scriptura explicat, quae ad scripturam translativam pertinet.
Summa...
De hoc translatio scripsit.
Quod ad hoc adscriptum est, quod ad hoc adscriptum est, et adscriptum est.