 So let's go ahead and actually implement out this map one of the reasons why we called it a map here's because if we're looking in Java's world It refers to a dictionary as a map now one of the things I said in the last video is this idea that map the The class of map in Java is an abstract class. There's actually a lot of different variations to it and how it sort of handles certain operations like lookups or storage and so We don't just magically get to you know, just use a map, but we do get the ability to come in and say something like Hash map now that hash map is just gonna be one of the variations Inside of all the difference We actually also have something called a tree map and we also have something called a link hash map Just different variations again. We'll take a look at them in a second. So let's say I came in and I'm just gonna throw together really quickly My my implementation of my my maps so I come in public static void main string args and Aha, I finally I'm gonna make my map now. We remember in polymorphism. I could call this a hash map or a map I can call it anything inside of its Implementation hierarchy, I want to use map in this sense just because It's a it's one step above I can still kind of work off of this especially when we start changing Hash map to tree map and link match map. I don't link hash map. I don't have to Really do much difference. The problem is we're starting to get into a quick introduction to the difference between an array and sort of a Dictionary if we will so you notice we got rid of the idea of an index when we started talking about maps dictionaries One of the things that we have to deal with now is what element? What is this? It's a character We know but it could be anything I could just like I was saying before I could turn this into You know another I Could turn it into that that's a terrible version since cats there, but it could be any Object, let's just kind of use an o for that. Oh Object It could be any data type that I want it to be and so as a result one of the things we have to sort of implement is Generics So what's a generic you may see this sometimes in you know different? Implementations out there on the internet and whatnot, but there's some class that someone built and right beside it You see sort of this kind of carrot sign and then maybe an e All that's telling us is that? This can be any Data type that we're dealing with if I want multiple that I'm gonna be dealing with a lot of them Guess what? I just throw a comma in there and I have some other e I wouldn't call it e because that's the same data type But you get sort of the gist of what's going on there can be anything. I want it to be we just use e For simplicity sake We're actually gonna do that exact same thing here inside of map now maps already been implemented So we don't really have any problems kind of going in I Still use that now if we kind of look I'm using DC and M for my keys over here So for our sake, I'm gonna say that the key In my map is a character data type I could use char, but I'm just kind of being fancy with the the capital character class Then I would separate by a comma because now I have to look at what my element is just like when we were dealing with an Array a traditional array. I would put whatever data type and then square brackets same kind of concept dog Could be anything I make it and for our sake. We'll just say it's a string I'm gonna call this M just to kind of model myself over here. However, this is where things are different If I just came in and did that let's implement that and let's see what happens if I compile and run that Let me shrink this move it into a reasonable view Java C test map Dot Java I Get in there. Ah, look at that map is abstract cannot be instantiated This is why we implemented that we imported a hash map as well. The idea is I can come in and say hash map Now if I compile this, oh It's complaining about this unsafeness and that's actually because I didn't include the good old Sort of this was a generic class as you can see simply resolving that takes care of that now Inside of my previous implementation. You see I did m.insert Java being Java does not use the idea of An insert. However, it uses in our case Put no difference, but the kind of implementation is now instead. I'd come in and I'd say in my sake my character data type and then my string element and As we can kind of see for cat and monkey. I Can do the exact same thing see for cat and M for monkey. All right. Everything seems honky-dory so far. That's perfectly fine One of the things we can do with this is we can Do simple things first. We'll do a traditional system dot out dot print L in on dial M for Anyone who gets that reference bonus points M dot look up All right, I think it's get off the top my head. I can't remember get we come in we Compile I was get a ha ha and then I run this Java test map Dial M for monkey Notice all I had to do here is instead of looking up Monkey I could actually just tell it my key. So if I came in and said Get M Dial M for dog Doesn't really work because you know stuff, but if I wanted to see every element That's actually kind of a really nice implementation and this is where we're gonna see the difference between a hashed Tree and linked hash map. So in our sake, I'm gonna use the for each Version of a for loop the idea here is that I now I'm working off of a colon And I don't have some index. I don't have the luxury of that one and two So I can't just do a for I and I Zero to size because I don't I can't I don't have indices instead I'd come in and I'd implement something over on that side as in that entry set that's My I don't want to say array, but that's my collection now And what that's gonna give me is not just dog cat monkey or DCM That's gonna give me that collection that entry if we will In fact, I'll call it a map dot entry. Haha just to kind of give you a hint I'm gonna I want to get the entry of those that key and that element and that's actually what I would put over here I would say map dot entry and Just like I did up here Where I said I had a generic of a key of a character and an element of a string I do the exact same thing here. There was a Character key and there was a string element and I'll just call it entry for the sake of simplicity sake So now that I've got these I'm not you know gonna jump too quickly yet, but I can come in and I can say Character key equals entry dot get key It seems pretty straightforward what that will do that'll grab the the D the C the M string element Entry dot get What do you think it is? It is not element. It is value. Oh, that's not terrible. You know we Values a little bit more of a generic term than element and you find a lot of times that get value is what people implement But the interesting thing is when we come in system dot out dot print L in key Will be my key Slash T element Will be my element And if I came up here Compile this and ran it Huh Notice that part right there see that's not my first entry Why is it appearing first? Well, that's actually what I was talking about at the very beginning some Hash map for example doesn't actually store them in any particular order. It's just kind of whatever wherever. It's available in its self Tree maps very similar. We're gonna get the same Implementation we're gonna get the same look and feel inside of a tree map and The only difference here is in this implementation. This is an alphabetical order Let me add a few elements in just real quick to And three we'll say so we have an a for alligator We have an e for elephant and we have a r and r for rat So we're talking about this being a tree map right now The tree map is going to put them in alphabetical order of their keys So as we can sort of see a c d e m r everything's in alphabetical order If however, I did it with a hash map right a hash map There is no particular order. Oh look at alligator and then we got rats and then c d e m There's not a given order to it. It's just kind of however they get stored That's fine sometimes But what about that linked hash map since that's sort of the last one that we haven't touched on yet linked hash map Linked hash map This is going to allow it to kind of be stored in the order. It was put in so it should say d c a e r m d c a e r m Which one is better where they're all pretty much the same It's rather more what you want to do with them if I need them to be an alphabetical order for my look ups Tree map if I do need them to be in the order that I inserted them linked hash map if I just need them to be stored in some Happ hazard way that doesn't really care about order hash map