8.12 LinkeList
Hello everyone welcome in this new course that will be devoted to Linkedlist The LinkedList class is a collection that ... can contain several objects of the same type Like ArrayList The LinkedList class has all the same methods as the... ArrayList Because they both implement the List interface This means you can add Delete Or edit items ... But first of all it should be known that there is a difference The ArrayList class has a regular table inside When an element ... is added, it is placed in the table If the table is not large enough, a new, larger table ... is created to replace the old but. in the LinkedList class LinkedList stores its articles in "containers". The ... list has a link to the first container and each container has a link to the next container in the list. To add an item to the list, the item is placed in a new container and that container is linked to ... one of the other containers in the list. I’m going to start by showing you how to declare a LinkedList so for the ... to do it is exactly the same as the ArrayList you have to put LinkedList then you have to put the type of element we ... will put then the name List new LinkedList It’s exactly the same That ArrayList As I said earlier They ... have the same methods So we will put For example a country name We will use the method add ... France Then another Germany We’re going to Belgium Then we’re going to display all the elements We’re going to compile And ... in the console we have The elements we put In our listPays on the other hand we have to know ... that linkedList Provides several methods for perform some operations For example we have the addFirst method so add First That ... allows to add an element at the beginning of our list So we can put For example China And we will re ... display Our List As you saw the difference The first List then the second There China that has ... been added there are also other method as addLAST BY EXAMPLE Who will add to the last From our list ... we will put for example Ghana To the last fine we have Ghana Then there is the method ... remove removeFirst that will remove the first element removeLast Who will remove the last element So China And Ghana will ... are remove Excuse I will show you As you saw they were removed We can notably display The ... last elements getFirst or getLAST As you saw first element France last element Belgium I hope you understood ... this brief introduction In the next course we will do exercises to understand well See you soon