 Hey everybody, this is Brian and welcome to the 25th Java tutorial. Today we're going to be discussing the linked list and you see we've got this cute little graphic here. This is what a linked list looks like in memory. We're going to come back to this because I don't want to confuse you just yet but I want you to kind of understand that the individual items of the list are actually linked together in memory through pointers. Like I said, we're going to come back to that. Here's our old code, the ArrayListTutorial. If you haven't watched the 24th Java video, Interfaces, Generics, and the ArrayList, I implore you to go out and do that because we're going to use the exact same code. And in case you're too lazy to go watch it, I'll just explain it real quick. You have your ArrayList with a generic of a string and the name is Numbs and you're making a new ArrayList and with the strings and you call the default constructor, you're adding three items, the positions 0, 1, and 2. You're removing position 1, which is this guy right here, and then you're enumerating over these. And I've added some comments here, ArrayList, Fast enumerations, LinkList, Fast inserts and deletes. Hmm, what do we mean by that? Well, an ArrayList is under the hood just an Array. And in an Array, the way it's dealt with in memory is each item is next to each other. So when it looks, it just grabs the next section of memory. It's very quick. It can just go right down the list without stopping. A LinkList is different in that each item is linked via a pointer to the other item in memory. Sounds really confusing, I know. And believe me, to use these, you don't need to know any of that. But what you need to know is an ArrayList is faster at enumerating, going through each item, and a LinkList is faster at inserting and deleting, which is what we've done here. Now to show you the power of an interface, remember both the ArrayList and the LinkList follow the list interface. Let's just copy and paste that. Notice how it starts complaining that we don't have a reference, so let's just copy and paste those. Suddenly, everything's fine. And when we run the code, it runs exactly like it did before, except for now we're using a linked list. That's because it follows that list interface. So no fuss, no mosh, you can switch back and forth between an ArrayList and a LinkList at will at any time. So if you're running your code, and you're using, say, an ArrayList, but you're doing a lot of inserts and deletes in the middle, and it starts slowing down, switch over to a LinkList. I'll bet you it'll run faster. And vice versa, if you're using a LinkList and you find that you just, you know, you fill the list, and then you go back and forth through it like 900 times looking. It's going kind of slow. Switch to an ArrayList and it'll go much, much faster. Now back to Wikipedia here in this graphic. This is what I was talking about. If this was an Array, these would all be contagious in memory, meaning they would be all next to each other. So the computer would just start at a position and just zip right through. Now a LinkList is different. These can be all over in memory at different addresses, and it uses a pointer. If you don't know what a pointer is, it's like a bookmark. It points to another location in memory. So let's say if we were to delete this 99, you drop a new one in and it would automatically link those together in memory. So when it hits this one and you say, I want to get the next one, it reads this pointer and says, oh yeah, it's over at this position. And then, you know, this one to this position, et cetera, et cetera. I know that sounds confusing, and believe me, you don't need to know any of that to use ArrayList and LinkList. As long as you understand the basics of the list interface, you'll be fine. This is Brian. Thank you for watching. I'm Brian Bell. I hope you enjoyed this video. Educational and entertaining.