Now if we want to uh use the first element right so how can you do that so uh just if you want to get the first element we use dot gate method okay so let me print that for you guys, uh you can see that again you need to under like use the class you want to execute I just you can say orange so what actually happened in at least it starts with zero whenever you are using any links the indexing start with zero with list okay you need to remember that not with 1 it actually starts with 0.


Now if you want to go for set something okay and for free of for list you can say one thing it actually maintains the insertion order you can say first I insert orange so it actually takes orange first then I insert apple it takes the apple right then I insert grips it took grips so it does not change the insertion order right it maintains the in the way you insert your data into the list okay and then uh if you want to say something right so what we need to do fruit list maybe I just want to change orange with uh guava right so that time what I need to do fruit list then dot set see you can see first is ink that is the index number you need to provide then the string the data you want to replace with the right.


This is one I'm going to take now I am going to do what that first index right to zero then what a data I want to give that is right now okay so let me see uh my uh program is working or not yeah we are gonna use this so this is I didn't print it now let me print it so let me write that the first we use plus sign if you want to like contact something this is the way you uh if you want to add some text with your output this is the way we can do that now after so now I am going to print the list we have changed right.


Now I'm going to write this is the converted list you can see right let me run it uh yeah see the converted list has guava in the first index right we can change the first element of our list successfully using set and gate method right but if we want to remove something if we don't want anything from our list right so what we will do so again the same thing you need to write your listing right now I'm writing fruit list dot remove we have a remove function then you need to provide the index number right so maybe I don't want grades, so this will be our 0 1 2 so your that index will be 2.


I provide the index number and that semicolon always you need to write semicolon in your code that is the main thing about java so let me check if my uh remove function works or not yeah, so that is after removing the list so yeah you can see the first uh list we had that is orange apple and grips after that we have the converted list that is guava apple and grips right now we want to remove grapes from our list you can see we successfully remove grapes from our lip uh from our list that is guava and apple now we have guava and apple right this is how you can manipulate your arrow list these are the main uh function we have for our array list there are many functions we have you can go you can explore these are the basic function you really need to know about if you want to use an array list.


If you want to manipulate our list okay or maybe we can sort our list but I just need to check that if we can do that, so these are you can see these are the list these are the methods we have for the list so if you want to see the size of your uh um list you can see this all right I just give me the list of this size of the list yeah it's giving me two so my array size my list size is two right so let me write it for you guys, yeah you can see I just need to use release.java okay so yeah my list size is 2 okay, so this is the main functions main methods we have to uh manipulate or to use our array list, yeah so you can see I have already added those things that uh yeah that how can you use add function in a list how can you use state function in a list I have shown you guys.


If you want to access any uh element from your list how you can do that using dot get function and if you want to use uh if you want to remove something from your list you can use remove function but let me tell you one thing guys while you are actually increasing the number of the list uh the number like the size it grows in early that is 50 50 percent of its size so always remember that that always uh release grows with the 50 of its size, so these are the main key point you need to understand when we talk about collection so when you go for an interview so they ask you this basic questions that how what do you think how the arrows go okay or how can you add something in your irony, so these are the main thing you need to understand when you like to start a learning collection framework okay.


Now I will talk about the linked list but what is a linked list link list is a linear data structure and all the elements are linked with each other when I'm talking about the link with each other what does that mean okay so basically uh linked list has a two-part right one part contains the value you have, and another part contains the address for the next element right and each element has the reference to the next element that is nothing that each node we refer to every element in a linking that is a node and if each node contains one part is the value and the next part is the address for the next element right.


Linked lists are almost the same with the adding but in linked links uh the memory location is not contiguous okay and they are linked with each other right using pointers now comes the head of the linked list but the head of the link leaves contains the address of the element, okay but it does not contain the data and when it comes to end of the early cliff the last limit of the link list is doing not contain any address because that is last it only contains the value of the linked list like, so these are the main thing you really need to know about list linked list we are talking about okay.


Every element in the linked list is called a node and the linked list can contain duplicate value as well okay and link this increments the list interfaces that we saw in the before part as well it uh implements the least interfaces and it maintains the insertion order as well right but why do we need linked list okay because the linked list has a good memory allocation the alignment of the memory is nice, uh the inserting deleting searching element using linked list is quite easy that is not easy with the array okay and if you do some uh deletion or uh adding some elements in the array that are very expensive for the linked list you can do it easily okay and Likeliest provide the dynamic allocation as well his memory allocation is good.


This is why we really need to be linked list’t okay Lings also had that faith and gate mirror as well and in linked list uh in like in the performance of linked list using add and remove is far better than Arrays and what's in gate and faith method right this is the thing you need to remember when we uh start talking about collection framework okay so now let's see what types of linked lists we have right we have a single linked list we have double at least.

Post a Comment

Please do not enter ant spam link in the comment box

أحدث أقدم
satta king gali