Linked List

Complete Step By Step Java for Testers Java Advanced - Collections Framework
7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.19
List Price:  €119.27
You save:  €34.08
£74.77
List Price:  £104.68
You save:  £29.91
CA$137.78
List Price:  CA$192.89
You save:  CA$55.11
A$150.31
List Price:  A$210.44
You save:  A$60.13
S$129.19
List Price:  S$180.88
You save:  S$51.68
HK$777.80
List Price:  HK$1,088.96
You save:  HK$311.15
CHF 79.59
List Price:  CHF 111.43
You save:  CHF 31.83
NOK kr1,013.63
List Price:  NOK kr1,419.13
You save:  NOK kr405.49
DKK kr636.11
List Price:  DKK kr890.58
You save:  DKK kr254.47
NZ$172.27
List Price:  NZ$241.19
You save:  NZ$68.91
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,200.05
List Price:  ৳17,080.55
You save:  ৳4,880.50
₹9,057.54
List Price:  ₹12,680.92
You save:  ₹3,623.38
RM409.68
List Price:  RM573.58
You save:  RM163.89
₦144,900.08
List Price:  ₦202,865.92
You save:  ₦57,965.83
₨27,977.78
List Price:  ₨39,170.01
You save:  ₨11,192.23
฿3,144.12
List Price:  ฿4,401.89
You save:  ฿1,257.77
₺4,257.57
List Price:  ₺5,960.77
You save:  ₺1,703.19
B$541.88
List Price:  B$758.66
You save:  B$216.77
R1,687.37
List Price:  R2,362.39
You save:  R675.01
Лв166.64
List Price:  Лв233.31
You save:  Лв66.66
₩147,438.25
List Price:  ₩206,419.45
You save:  ₩58,981.20
₪322.26
List Price:  ₪451.18
You save:  ₪128.91
₱5,910.90
List Price:  ₱8,275.50
You save:  ₱2,364.60
¥15,573.94
List Price:  ¥21,804.14
You save:  ¥6,230.19
MX$1,801.20
List Price:  MX$2,521.76
You save:  MX$720.55
QR363.83
List Price:  QR509.38
You save:  QR145.55
P1,322.75
List Price:  P1,851.91
You save:  P529.15
KSh12,873.43
List Price:  KSh18,023.31
You save:  KSh5,149.88
E£4,730.87
List Price:  E£6,623.40
You save:  E£1,892.53
ብር15,598.69
List Price:  ብር21,838.79
You save:  ብር6,240.10
Kz91,690.83
List Price:  Kz128,370.83
You save:  Kz36,680
CLP$91,270.93
List Price:  CLP$127,782.96
You save:  CLP$36,512.02
CN¥705.37
List Price:  CN¥987.55
You save:  CN¥282.18
RD$6,346.47
List Price:  RD$8,885.32
You save:  RD$2,538.84
DA12,964.71
List Price:  DA18,151.11
You save:  DA5,186.40
FJ$227.15
List Price:  FJ$318.02
You save:  FJ$90.87
Q764.64
List Price:  Q1,070.52
You save:  Q305.88
GY$20,885.90
List Price:  GY$29,241.10
You save:  GY$8,355.19
ISK kr12,616.33
List Price:  ISK kr17,663.37
You save:  ISK kr5,047.03
DH918.43
List Price:  DH1,285.85
You save:  DH367.41
L1,687.62
List Price:  L2,362.74
You save:  L675.11
ден5,239.78
List Price:  ден7,335.90
You save:  ден2,096.12
MOP$800.52
List Price:  MOP$1,120.76
You save:  MOP$320.24
N$1,684.29
List Price:  N$2,358.08
You save:  N$673.78
C$3,674.23
List Price:  C$5,144.07
You save:  C$1,469.83
रु14,445.11
List Price:  रु20,223.73
You save:  रु5,778.62
S/336.11
List Price:  S/470.57
You save:  S/134.45
K430.33
List Price:  K602.48
You save:  K172.15
SAR375.18
List Price:  SAR525.27
You save:  SAR150.08
ZK2,303.63
List Price:  ZK3,225.17
You save:  ZK921.54
L433.54
List Price:  L606.98
You save:  L173.43
Kč2,066.70
List Price:  Kč2,893.46
You save:  Kč826.76
Ft32,660.30
List Price:  Ft45,725.73
You save:  Ft13,065.42
SEK kr926.89
List Price:  SEK kr1,297.69
You save:  SEK kr370.79
ARS$143,373.53
List Price:  ARS$200,728.68
You save:  ARS$57,355.14
Bs689.81
List Price:  Bs965.76
You save:  Bs275.95
COP$380,209.72
List Price:  COP$532,308.82
You save:  COP$152,099.10
₡49,937.50
List Price:  ₡69,914.50
You save:  ₡19,977
L2,628.31
List Price:  L3,679.75
You save:  L1,051.43
₲670,577.05
List Price:  ₲938,834.69
You save:  ₲268,257.64
$U3,917.97
List Price:  $U5,485.31
You save:  $U1,567.34
zł359.54
List Price:  zł503.38
You save:  zł143.83
Already have an account? Log In

Transcript

Hello, guys, welcome back to the next tutorial. And this one, we are kind of talking about our collections framework and to our next class discussing about collection framework. So today we will talk about linked list. So we'll continue our discussion from the ArrayList. Let me just quickly bring up the eclipse. And let me just show you.

So last time, we discussed this ArrayList, right. And today, we have our linked list. So I just have an empty class. And there's nothing into it. I'm just going to show you very quickly that pretty much a lot of things are same and common in these things. And we'll talk about the differences and all those things.

So let's see. So let me just do one thing. If you guys see this is an empty class linkless demo, and from a list demo, what I'm going to do is I'm going to copy everything, and I'm going to copy everything till here. And I'm just going to simply paste it and next thing I'm gonna do is I'm just gonna remove this to link list. And same thing I'm going to do to this thing, right. So if you guys notice, what I just did is I just replaced ArrayList with linked lists, and everything stays the same.

If you guys notice this add method, same size method is same, then retrieving good method is same. And pretty much removed method is same, everything is same, like it works like a charm. If I just run it, you guys can see it, all the things work exactly like the ArrayList. So they are pretty much exactly the same thing. And there are different so I'm going to talk about those, but they're almost like same, so you guys can use them interchangeably. And if your list is small, definitely you don't even have to worry less if your list is considerably smaller, like hundred or 500 items or something like that, or maybe even thousand items.

You don't even have to worry it just pretty much the exact same thing. So you know, what are the differences that so let's talk about Got it. Let me just actually kind of start from here and as follows. So, usually, maybe, just let me comment out something like, okay, so ArrayList usually there's a base right that I talked about. So how would they look they would look something like this. And let's see if I have integers like 012345 and six something like this right?

They will look something like this there anyways. But linkless is actually kind of it can contains elements where each element has a reference to its previous element and to its next element. So, you can you can see some, imagine something like this. So let's say zero, and then it has a reference to next element then one and then it has a reference to next element, then to And then actually, if you guys because if you have to do this, we have to refer the back as well. So one has the reference to zero and then two has the reference to one. So basically they point to each other and that's how linkless works.

So where is the difference? difference comes in, always use a realist when Okay, let me just write it write it explicitly. So realist when you have to add at the end and remove from the end, right? And getting is fast. Okay linkless when you have to add at the beginning Remove from the beginning. All right, so why why so as I talked in the last tutorial as well, right?

When we are talking with ArrayList, if you remove something from the beginning, like let's say you remove one, it has to relocate everything. And it has to just bring this to a pair three pair. Otherwise there's there's got to be an empty index. And that's not what we want. So this can be like a memory leak and all those sorts of issues in Java. So Java handles it by moving all these elements, shifting them by one.

So the array relocates itself and Java does it. We don't have to do it. But yes, internally, it causes some, some memory and some CPU uses to Java, right. So that's why it takes more amount of time. While in linkless, because it's just a reference, it's a pointer sort of thing both ways. So if we remove something like this, it just changes the pointer to two and this pointer to zero and then it just works like anything.

So it's fast. That's the difference. So What I'm gonna do is I'm going to show you real quick examples. And maybe one more thing. So since they both implement the list interface, so what we can do is guys, instead of kind of declaring things like this, we can declare simply like this. So I'm just gonna change this to list.

And maybe here some, maybe, let's say link list. Right? So it implements the list interface, right. So anything that implements the list interface can be just declared like this starting from list and type we need to give, and we can just name the exact type that we want to implement. So linkless is the class that we are implementing that we're using. So here, let me just change it to integers because I'm just going to create them create a method, so integer, and not integers integer.

And let's declare one more. So in teacher and ArrayList, and then New ArrayList and then integer, right. So that's how we can create both of them. So if you guys see, we just created an ArrayList and linked lists with the same way, right? We use the same interface and it's all done. Right?

So sounds good, pretty, pretty nice and decent. So you know what, that's all I wanted to talk about in this tutorial, I just wanted to show you that we can actually implement these things using the same list and replace and this is just a list now we can add anything to it like a list dot add or something anything we can use, and it has like few methods also like so add has a method for adding teacher right, we can add at an index. And then other than this, I wanted to show you one more method. So if I say add, it has this method as well. So this is like specifying the index where you want to add so I can specifically add it Maybe second index. And I can add the element, whichever element that I want to, or maybe 10, because it sets an integer, right.

So I can specifically add stuff to different indexes in this as well. So that's also one of the Add methods. So that certain done guys, that's pretty much it I wanted to show in this tutorial. In the next one, I'm actually going to be comparing the performance of these in different conditions and talking about the differences in these things, more differences. So these are the differences that we already saw. But we'll talk about the differences in action actually will actually do those things.

So he asked him for the next lectures, guys, thanks for attending this one. Thank you.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.