Java Essentials - Linked list in java
8K views
Oct 24, 2024
Java Essentials - Linked list in java
View Video Transcript
0:00
In this video we are discussing linked list in Java
0:05
So link this is another example of collections in Java and it provides the link list data structure
0:12
We know that in case of link list it is consisting of multiple number of nodes and where each and every node mainly will have the two fields one is the information field also known as info field and another field is the next field which will be holding the reference of the next node and that is known as the link list
0:29
structure. So in this video we are going to discuss link list in Java. There is another
0:35
collection example into further details. So what is link list? So link list is another
0:42
example of Java collection and it provides a link list data structure and it also
0:49
like the addy lists and you can have the functions like your add, remove, clear, find
0:55
elements in the link list also. So these operations are allowed in the link
0:59
list collection so let us go for one practical demonstration where you will be
1:04
showing that how this link list collection can be used in our Java code so here
1:09
is the demonstration for you in this program we shall deal with link list class objects so here you can find that we creating one link list the object name is I nt list which is containing integer
1:23
wrapper class type of objects so how to add new members to this I NT list the
1:30
method is add and here you are passing 10 20 30 40 and 50 as input arguments so
1:37
after adding all these members we are going to print the size of this I and
1:42
list and also the current content of this INT list the size is a method with the help of
1:48
which you can get the number of members this link list is having so let us go for
1:53
the execution you can find that it is printing the size as five because here
1:58
we are having five elements or that these elements are nothing but integer
2:02
wrapper class objects and we are having the values say 10 20 30 40 and 50 in the
2:08
order in which they added up with this link list class object INT list. Now here we are defining one array. This is a simple array
2:18
INT array and name of the array is array having got elements that is 515 30 80 60 and 25
2:26
So now we are going to define another array list. So here the add in this object is
2:30
a RR list is equal to new add a list and then with this add a list we are adding adding this items we adding item picking up item one at a time from the integer array
2:42
and here you are using this for each loop where item will get
2:46
initialized with one of the members one at a time depending upon the iteration
2:51
from the integer array array so now we are going to print this add list so the
2:56
addiless size is getting printed the method is same that is the size and here
3:01
we are printing the current content of the array list so here you can find that
3:05
here you are printing this array list and there we are printing that link list
3:09
here so let us make this one it is better let us go for this array list so this
3:14
array list size and the respective contents are getting printed now let me go for
3:19
the execution to show you that the link list size is 5 the content is this
3:24
the array list size is 6 and the content is this one as we expecting okay so
3:31
as we are expecting we are getting this output now see in this I and T list we're adding
3:36
all the members so the method name is add all we're adding all the members from
3:41
the index number two from the index number two onwards that is the add a list
3:46
content will get inserted from the index number two all the members of this add a list how many members this ad list is having this ad list is having six members 5 15 30 80 60 and 25 so all these members will get in certain
4:00
starting from the index number two and later we are going to print this i nt list
4:05
size and the current content of the i nt list we know that i nt list is nothing but link list
4:11
class object and which is defined to hold the integer wrapper class objects as its content
4:17
So now let me go for the execution. You can find that the linkless size is 11. Why 11? Because 5 plus 6 is equal to 11. And from the second index onwards, you can easily find that from the second index onwards. I'm just going for this. So location number 5 onwards rather. So we are going to have this set of elements, you know, we're going to have this set of elements that is 5, 15, 30, 80, 16, 25. They're nothing but the ad list content. And this
4:47
have got inserted starting from the index two and from the zero place and the
4:52
one place where having this index number zero and one is still holding ten and
4:55
twenty and from this particular index we're having this thirty forty and fifty
5:00
fifty as is well so in this way in this demonstration we have shown you that
5:04
how to define link list objects and how to all different methods from this
5:09
object itself thanks for watching this video
#Computer Education
#Computer Science
#Java (Programming Language)