Hello.
Students, in this lesson, we are going to learn what connections are.
This is very important topic because connection interface is implemented by all connections implementations
in Java.
That's why understanding of collection interface is a key for understanding of all other collections
in Java.
So today our primary focus is learning of collection interface.
I'm going to show you your middle class diagram, will understand what it is and how we can use it in
the future.
To understand a type structure during the lesson will understand what methods collection interface has
and why do we need them.
We will review abstract and default methods of collection interface and at the end of the lesson, we'll
look at the collection source code.
Let's start.
I suggest that our lesson from this slide on this slide, you may see visualization of what the collection
is to understand collection.
Imagine the back, the big back where you may put all your stuff.
You might put your product, user card and all other objects, and you can retrieve exactly user or
product or cards by its index like you did in array.
What you can do is to put all things from your back on the floor and go over them one by one.
We're also going to learn in the separate lessons, the specific type that is developed to go over each
element.
What else we can do with these?
Back to answer this question, let's take a look at collection interface and we'll learn what else we
can do with our bag of elements.
Here is a class diagram we are going to learn with your UML language that is unified model and language
in detail a bit later.
But this is what is used to call class diagram.
And while being a software engineer, you are going to see such diagrams very often.
What do we have here?
We can see that collection interface extends a terrible interface, a terrible interface.
We are going to learn in a separate lesson, the same as Iterator.
But in short, this is an interface that stands on top of all collections interfaces to make sure that
it will be possible to iterate over each element in each implementation of collection interface.
Today we are going to focus on collection interface and we will start learning it from this class diagram.
Let me give you a quick introduction regarding symbols here.
You can find indication whether this type interface or no, that is our interface text right above the
interface name.
We can see that it's Arabel and collections, both interfaces here.
We can see list of methods that each specific type has, plus some means that this method is public.
After that goes method signature.
That is method, name and method parameters followed by colon.
And we can find return type right after the column.
For example, the first method in the list in collection interface is this method without parameters
that returns in value.
Does it make sense now?
This knowledge will help you to understand class diagrams written down on human language.
And let's answer our original question.
What else we can do with this back?
We can check a number of elements in it.
That is what size method does.
We can check if this bag is empty or no.
That's why when it is empty, we can ask our back elements, does it contain some specific element or
no contains measures that will help us with this task.
We have also matters that control collection of elements, interior objects and methods that can turn
collection of elements into the array of specific types.
For example, if your collection contains only elements of product type, we can convert our collection
into of product elements, but not in the array of objects.
If you don't want, can you feel the difference?
After that?
We can see methods that we already kind of discuss.
Let us add methods.
I can add elements to the collection.
I can also remove elements from the collection and to remove elements from the collection, I have to
pass this exact element.
Another important behavior, we can check whether this collection contains all elements that other collection
has.
That is our contains all method.
We can add all elements from one collection to another.
To do this, we have to use at all method and we can remove all elements from the current collections
and other collection has that is our remove all method and believe you can see on the slide that message
that we have just discussed.
Take out the collection as my argument.
If you want, you can keep only elements that are present in both collections.
To do this, we have to invoke retain all methods and positive reference to another collection into
it.
In other words, this message removes from the current collection all elements that are not present
in the collection that we passed as a method augment the methods that are left here are also describing
claims method will remove all elements from the collection and as you already know, equals and harsh
methods that are the methods that each object should have.
But the idea of specifying equals and Haskett methods in the collection interface is to put stress on
the fact that these methods should be implemented in an implementation of collection interface and that
these methods should override default behavior from object class.
And the last but not the least, massive collection interface is an iterator.
Pay attention to the iterable interface description now.
It is also the collection interface because it implements a terrible interface.
As you can see, Iterator method returns object of iterator type insert.
This object will help you to iterate over each element in your collection.
We are going to learn what Iterator is in the separate class and that is how our collection interface
that is something.
What do you have to remember?
We just have such interface and what we can do is just to remember it just as an alphabet.
We don't ask why a letter is written exactly in this way.
We just learned that this is a letter and how it sounds.
And when we know that we start building words with this letter, the same as here, we just have to
learn collection, interface and learn how to use it.
So here on the screen, you may see only abstract methods that should be implemented in each collection,
but there are a few more other default methods in the collection interface.
What are they to answer this question and to give you otherwise how constantly learn new things and
check information that you get not only on this lesson but in any tutorial?
Always investigate the source code of your conversion.
I believe you remember how to add source code, your code editor and where you might find it.
Let's open collection type to investigate the source code and find methods that we didn't learn yet.
I press control shift and simultaneously I have to type collection.
I need collection from Java with your package and here this and here on the right, we might see a list
of all methods that are present in this interface.
It looks like we went over all abstract methods.
How I learned which method is abstract and it's is a small a letter that stands for abstract.
But we didn't cover in our presentation methods that have Glitnir.
What are they?
Here's the overloaded method to array it.
Just take specific functions that will describe how to convert collection to a right to be able to apply
this method.
We have to know how to write in the functional style in Java and understand what functional interface
is.
Don't worry.
This topic also will be discussed in the separate lesson.
I just want you to understand, at least on the high level, what these default methods are about.
Remove method, this method takes predicate, predicate is a specific type that can return true or false
based on the specific function that you will pass as a method argument to this method.
It will identify which element should be removed.
For example, you may describe functions that will return.
True in a case product price is more than one hundred dollars, and in case this function will be applied
to this specific product and collection, it will be removed and this function will be applied to each
element in the collection you might find while loop here and see that Iterator is used to go over the
collection as a condition for each element in the collection and remove it in case it satisfies the
condition.
Also, there is a default method that creates iterator.
Split Iterator is a specific type that can traverse and make parts of elements of the source collection.
And here is a method that exists in all implementations of collection.
Interface Stream Method joins the collection into stream of elements or in other words, sequential
stream of elements.
String Mapei was introduced in Java version eight and it was a breakthrough in this course in separate
lesson will be on stream API and we'll learn how to use it as a practical exercise.
Will even rewrite our home tasks with the help of the Stream API.
And here is a massive, transparent stream.
According to documentation, it returns possible parallel stream with the current collection at its
source.
Now, let's recap what we have learned today, so they've learned what the connection is, we try to
imagine collection is a back for our understanding.
The day you saw your first UML diagram, class diagram.
Now you know how to read class diagrams to understand the type of description we reviewed all abstract
methods in collection interface.
And after that, we reviewed the collection before methods.
Also during the lesson we investigated source code of collection interface.
That's all what I have for you for today.
Thanks a lot for your attention.
See you in the next lesson.