 Hello everyone. Let us continue with our topic on collections. Next video, this video is based on linked list and collections. As we have seen in the previous video, now we are going to see linked list and collections. What students are able to learn after this particular watching this video? First, they are going to see various methods which are available in linked list and students also will be able to write a program in linked list. So, what is linked list and why it is important in Java? Link list, as we all know that in data structures, we have a concept called as linked list. Here in Java, it is going to work on that principle. Link list where two nodes are connected with one another. There is a link between two nodes. Likewise, we can have n number of nodes. Here, which data structure is going to use, it is going to use a doubly linked list. Here, you can see the last point. It is based on doubly linked list in Java. That means a node is connected to next node and next node is also connected to the previous node. Some important points. It can contain duplicate elements. Linkless maintains an insertion order. It is again non synchronized. Here, manipulation is fast because it is going to work on the principle of linked list. In previous case, it was on array list where every array location need to be moved. In linked list, we know that if a particular element need to be deleted, we will just delete that element and the previous element will point to the next element and next element will point to the previous element. Therefore, there is no shifting concept over here. So, the time required here is minimum. It can also be used for stack and queue concepts. Okay, it works on the principle of doubly linked list. As I said, this is all details about the linked list. So, now moving on, how we create a linked list? First way to create a linked list is linked list its object equal to new linked list. So, here on object list will be created of type linked list with an empty element set. Second way is passing some other collection to it. So, linked list equal to new linked list some collection. So, let's say you have created two linked list in your program. So, another linked list content can be directly copied to this linked list just by passing its object. Let's say you have two linked list L1 and L2. So, this is suppose L2. So, L1 can be copied directly to L2 by writing just passing the object of L1 over here. That's how easier it is to copy the elements of one linked list to another linked list. So, now let us make our hands dirty by writing a program on linked list quickly going on to the linked list program coming to eclipse. Okay, this is what we were done in the previous video. Now, let us create one more file, one more Java file saying linked list demo. Okay, we will have public static void main finish it. So, another linked list program has been created over here. Now, here if I want to create an object of linked list it as I explained the steps it will be linked list its data type. Let's say I want to store string over here linked list 1 equal to new linked list of type string. So, here object is created by writing this line object list 1 is created. Okay, now if I if I want to append elements to my list it will be list 1 dot. List 1 dot will give you all the methods present in linked list. Okay, here popularly we use add again I want to add let's say this time Roshi okay list 1 dot add let us say take some random names Raj list 1 dot add Smriti ticket. Likewise, I can add elements to my linked list. Okay, if I want to display all this complete linked list same way as we have done it in our list for loop it is string string s in what string s in list 1. So, here I am going to write system dot you can write says out print here s that's it. So, here you can see let us see whether it will run fine or not. Yes, we are getting Roshi and Smriti. Okay, now instead of for loop as I said we can even use iterator over here. So, how I am going to use iterator iterator data type string it its object equal to the object on collection type on which I want to do it list 1 dot list 1 dot iterator I want to have an iterator that means I want to iterate to that particular through that particular collection type. So, while that particular it as an element that is as next we check by using a method called as as next if it is having an element we are going to print it how we will be printing it using a method called as it dot next element will be printed over here let us check once again. So, twice the output is getting this is for for loop and this is for while loop using iterator fine I hope you understood the use of iterator in case of this list iterator because it is a doubly linked list to prove that it is a doubly linked list we have some more iterator types available to move in forward direction and to move it in backward direction. Okay, if I want to come it in backward direction have something called as descending iterator which will display the elements in descending order that means the element which has been inserted last will be displayed first that is in reverse order in short it will be printing the elements in reverse order just change the iterator to descending iterator and rest all will be same if I run it. So, here you can see for loop is printing Rushi Raj and Smriti and iterator descending iterator is printing Smriti Raj and Rushi in reverse order that is the difference using iterator and descending iterator fine. Now, if I want to use some more methods in this case okay I can create let us delete this for loop okay let us take one more linked list linked list again on based on string list2 equal to new linked list string. So, here it will be list2. okay list2.add I will add some elements let us say Raul list2.add let us say I want to add here Sachin Raul Sachin list2.add one more element let us take the let us play Rohit okay like that I have added now suppose I want to copy this list1 into list2 directly okay that can also be done okay just by passing here while creating you can write your list1 everything will be added over here or you can even do this list2.add all add all what add list2 sorry list1 all the elements of list1 will be added here you can relate it both ways are valid so add all list1 so list1 will be added over here now if I want to check whether it has added properly or not we are we are using a descending iterator which will print it in reverse order okay let us check now Smriti Raj and Rushi okay I am printing your list1 instead of list2 it should be list2 if it is list2 it should do the job now that is Smriti Raj Rushi Rohit Sachin Raul it is exactly the reverse order what we have inserted okay likewise I can use or many other methods available in link list so list2. even I can do this after I doing this I can do that list1.clear if I do list1.clear it will clear the complete collection itself to check it you can run a for loop over here and check it for each loop you can use over here and it the complete collection type will be deleted okay now let us try to answer this question how many ways we can initiate a link list just now we have seen it the answer is two ways these are different popular methods that are used in link list that is not limited to this we have n number of methods included these are some of the popular methods add clear get first get last so get first is going to give me the first element get last method is going to give me the last element present in my link list these are some popular last index of what is the last index of like let's say you are not aware how many elements you have inserted okay add by by course of time you want to find like how many elements are present in my list that can be answered using a method called as last index of okay these are some of the references thank you