Map and HashMap in Java - Full Tutorial

Поділитися
Вставка
  • Опубліковано 5 жов 2024

КОМЕНТАРІ • 465

  • @gur151
    @gur151 3 роки тому +467

    Super underrated channel. With how little views your videos currently get, I'm surprised UA-cam even recommended them to me! You deserve a lot more viewers for how well you explain things, and I hope your channel gets the recognition it deserves soon enough

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +76

      Thanks! As you for sure already know, liking/subscribing/sharing/commenting all really help, so I really do appreciate it!

    • @thunderstruck2727
      @thunderstruck2727 2 роки тому +9

      At this rate his channel won’t be small for long.

    • @davidteklea1032
      @davidteklea1032 2 роки тому +3

      I feel the same way as you Gur.

    • @iskandar-9726
      @iskandar-9726 2 роки тому +1

      @@davidteklea1032
      +1

    • @blazing_yt2342
      @blazing_yt2342 Рік тому +3

      Amazing explanation man, you actually made mapping easier.

  • @millenialmusings8451
    @millenialmusings8451 2 роки тому +108

    the one thing i like about this channel is he doesn't waste any time. you can see he edits out speech pauses and filler words. very concise and engaging.

    • @SpideCooper
      @SpideCooper 2 роки тому +5

      yeah it didn't even feel like ten minutes just found this page and its already awesome

  • @yuto5636
    @yuto5636 3 роки тому +168

    I am a first year software development student and there are a bunch of stuff they didn't teach us. This video is quite useful! Thanks!

  • @youthought878
    @youthought878 2 роки тому +27

    I don’t understand how you can explain this stuff so easily. Seriously a true talent. Can’t thank you enough for the videos

  • @CarlosCed
    @CarlosCed Рік тому +7

    Sir, I’ve been binge-watching your videos for the last three days. You make it all so very simple and clear. Thank you.

  • @peterswrath
    @peterswrath 2 роки тому +13

    man if only my cs class was set up and taught like John. he explains all these topics, in the best simplest ways! love these videos!

  • @venkat757
    @venkat757 2 роки тому +3

    Man... You are hidden diamond 💎 in UA-cam and I found you very late..... You deserve more views than any other java related videos.... I am from India.

  • @shoaibaltaf705
    @shoaibaltaf705 3 роки тому +18

    I tell you now. You will become top code UA-camr

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +3

      Thanks for the words of encouragement and thanks for watching!

  • @azadassis3669
    @azadassis3669 Рік тому +5

    I have recently discovered this channel, and to be completely honest, it's an awesome channel to learn from. I have seen many channels teaching Java, but this one is different, the way the John teaches is captivating and holds your attention throughout the video. The videos are informative yet concise, and everything is presented clearly and accurately. I have been going through all the videos.

  • @PedrovoriskAB
    @PedrovoriskAB 2 роки тому +5

    man please.. please keep it up with ur videos.. plsssssssssssssssss they are amazing.. I am in the middle of a java bootcamp and they are really helping me out

    • @CodingWithJohn
      @CodingWithJohn  2 роки тому +1

      Thanks Pedro! I appreciate all the comments, keep up the learning!

    • @PedrovoriskAB
      @PedrovoriskAB 2 роки тому

      @@CodingWithJohn amazing !!! will watch all ur videos and also I am sending them to all my bootcamp friends..

  • @BernardVisagie
    @BernardVisagie 3 роки тому +4

    2:28, now in C# you can infer even more, and you would be able to write your Java as: HashMap empIds = new();

  • @crookedcrowe9215
    @crookedcrowe9215 2 роки тому +1

    I have a test coming up tomorrow and this guy is literally saving my life by making things simple and clear to understand. THANK YOU!!!!!

  • @jakedotnet
    @jakedotnet 2 роки тому +21

    9:09: The error 'Insert "Dimensions" to complete ReferenceType' refers to arrays. The primitive type int isn't a valid type to use here, but int[] would be a valid type, as all array types are reference types in java, even those of primitive component type.

    • @MarkSmith-vo1vn
      @MarkSmith-vo1vn Рік тому +3

      Oh because int [] array is an object as well. We just need to pass in an object, so it thinks we want to do the int[]. Makes sense thanks.

  • @mattmalan6
    @mattmalan6 3 роки тому +6

    Thank you so much! I've got this massive project due in a few days!

  • @flytoinfinityvivi
    @flytoinfinityvivi 5 місяців тому

    This video literally equals to an hour of studying trying to understand Map. You are amazing! Please never stop what you are doing. You actually make us beginners understand and well hopefully making us the future IT people (:

  • @aryanjoshi9703
    @aryanjoshi9703 8 місяців тому +1

    in ten minutes i am able to learn which others explain in double or triple amount of time and comprehended 95% of the video content , thanks to your explanation , thank you john sir

  • @ChickensAndGardening
    @ChickensAndGardening Рік тому

    I've been doing Java since the late 1990s and this tutorial still taught me a thing or two. Good job!

  • @ИваИванова-у8ш
    @ИваИванова-у8ш 2 роки тому +6

    Hey John.
    I've been watching your videos for the last few hours and so very glad I found you.
    I'd been struggling with making LinkedLists and HashMaps make sense in my head and your explanations + examples struck a note with me.
    Thanks a lot.

    • @CodingWithJohn
      @CodingWithJohn  2 роки тому +2

      Awesome, very glad the videos helped. Thank you for watching!

  • @Naruto_Uzumaki_
    @Naruto_Uzumaki_ 10 місяців тому

    I just wanted you to know that you're making a great difference in my academic life Mr. John! I appreciate your channel a lot!!

  • @hassanlearning4086
    @hassanlearning4086 Рік тому

    Spent hours reading book but explained it so simply. Thank you.

  • @ceciliacastro3093
    @ceciliacastro3093 Рік тому

    This video was really helpful. I´m studying engineering and I understood more in your 10 minute video than in a whole programming semester. Thank you form making student´s lifes easier.

  • @carriewright7247
    @carriewright7247 2 місяці тому

    Thank you so much John! Your videos are great! I love how I can learn what I need in just 10 minutes as opposed to the typical school setups we have all experienced in other venues that takes hours and leave you confused.

  • @dessa8242
    @dessa8242 6 днів тому

    I didn't know why you have fewer subscribers, I am the kind of person who does not understand things right away, but your video is so simple, and precise. I will understand if you do some rocket science courses too haha. Anyway, you are so smart enough and can readily explain things.

  • @To4ster0ven
    @To4ster0ven 3 місяці тому

    hello john. im a day before finals in one of the courses in java that i learn and this video has explaind the hashmap so well. thank you so much

  • @ReallyAqua
    @ReallyAqua 2 роки тому +2

    Why do you not have a lot more subscribers? You have helped me so much and you deserve to have a lot more. Thanks for helping me out on so many things!

    • @CodingWithJohn
      @CodingWithJohn  2 роки тому

      I've been lucky enough to go from about 10k a month ago to over 50k now and growing. So it's taken a long time but I'm on my way. Thanks for the kind words, glad you're enjoying the videos!

  • @dibjr
    @dibjr 2 роки тому +3

    Thank you, John! Your videos are concise, clear, and well presented. I really enjoy them!

  • @Zacfrappier
    @Zacfrappier Місяць тому

    3:47 for fanservice lol. Great videos, helping me get an A in my Java class this semester! I have to pause frequently to take notes, and often find new information that I missed when rewatching the videos. Although hard to keep up with unless your familiar with Java, I find the fast pace engaging and usage of concise terminology incredibly helpful.

  • @stevenschelling8452
    @stevenschelling8452 2 роки тому

    This is truly some of the best coding instruction I've found online

  • @RamblinTarhiel92
    @RamblinTarhiel92 2 роки тому +1

    I took notes to make myself a cheat sheet from this and work on my typing speed. Love these videos!
    HashMap name = new HashMap();
    name.put([key object or value], [Value or object]);
    adds a Key and a Value to the hashmap
    System.out.println(name);
    [Outputs:
    "{Key=Value ....}"
    System.out.println(name.get("Key"));
    [Outputs: Value associated with Key]
    System.out.println("Name.containsKey("Key"));
    Prints Boolean answer to inquiry -- does the "key" exist in the map? True.
    System.out.println("Name.containsValue("Value"));
    Prints whether or not map contains "value"
    Put overrides previous calls to put method on the same key
    hashMapName.replace("key", Value);
    will replace entry for key, but does not create new entries
    HashMapName.putIfAbsent(key, value);
    adds the key and value to map, if absent

  • @shahoodgmail
    @shahoodgmail 2 роки тому +27

    Your tutorials are bingeworthy. I already know and use Java but in all of your tutorials, I do get to learn a thing or two. Keep up the good work! 👍🏼👍🏼

  • @AtulPal-i5s
    @AtulPal-i5s Місяць тому

    It's an amazing video it explains how to use hashmaps in pretty short video. I'm learning springboot and I don't know about hashmaps so it really helps me to understand how the hashmap works and now I can use it.

  • @IralaPraveen-ku6zr
    @IralaPraveen-ku6zr 5 місяців тому

    you make to flooded lot of content into our brain in just a few minutes.thank you John.

  • @Diana_13.
    @Diana_13. Рік тому

    A huge thanks to you.The way you talk is so clearly also for none English speakers...🤝👏👏👏

  • @CharlesVasquezjr
    @CharlesVasquezjr 2 роки тому

    I just came across this video because I was struggling with Hashmap and objects...long sorry short, I hit subscribe, liked, and purchased the Java Bootcamp course.
    Message to all struggling: don't worry if you don't have the money to purchase the courses, I am sure you will find a way. I think God even while on unemployment I can make a purchase like this. If those can save up to invest in their future, I say do it!
    Thanks, John for the knowledge and keep doing what you are doing.

  • @justinbanza4751
    @justinbanza4751 3 роки тому +2

    Thank you very much for this video.
    it is very nice to learn with an enthusiast teacher.

  • @PieMongo
    @PieMongo 3 роки тому +5

    How do you not have more subscribers? You're one of the best channels I've seen, and I've seen ALOT haha.
    Maybe do inner classes for the next one? :D

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +3

      Thanks for watching! I like the idea, I'll put it on the list.

  • @gerdsfargen6687
    @gerdsfargen6687 Рік тому

    This guy rattles off it like an expert juggler. He is SO cool! We all could use the master communication skills like him here...especially for teaching programming! You got my vote!

  • @MichaelPayPlus
    @MichaelPayPlus 2 роки тому +33

    2:52 you never explained WHY you have to use new HashMap();.. it's because an Interface cannot be instantiated, only subclasses of an interface can. Because Map is an interface, you cannot directly instantiate it by using new Map(); you have to use one of Map's subclasses, in this case we chose Hashmap, which is a subclass of Map. We could have chosen any official or custom sublcasses of Map and this would still work.

    • @lifesucks9519
      @lifesucks9519 2 роки тому

      thanks that was informing but still, what are the subclasses available for Map?

    • @AcidiC727
      @AcidiC727 2 роки тому +1

      @@lifesucks9519 You can look up the Java API for Map, and it should tell you all classes that implement Map.

    • @lifesucks9519
      @lifesucks9519 2 роки тому

      @@AcidiC727 ok thank you

    • @mohamedibrahim-qm1cr
      @mohamedibrahim-qm1cr 2 роки тому

      But we use List an interface during instantiating instead of ArrayList basically both are viable at this point why?

    • @kous7av
      @kous7av 2 роки тому +7

      @@mohamedibrahim-qm1cr Hi! We cannot use List interface for creating a list. We must use a class (like ArrayList, LinkedList, etc.).
      This means the following two ways of instantiating a List are correct:
      List myList = new ArrayList();
      List myList2 = new LinkedList();
      Also, the following way of instantiating an ArrayList is syntactically correct:
      ArrayList myList3 = new ArrayList();
      Again, the following way of instantiating a LinkedList is syntactically correct:
      LinkedList myList4 = new LinkedList();
      But the following three ways are wrong:
      List myList5 = new List();
      ArrayList myList6 = new List();
      LinkedList myList7 = new List();
      This is because we cannot create a "new List()" since List is an interface and not a class.
      All the above correct and incorrect ways for the List interface are very similar to the correct and incorrect ways for the Map interface below:
      We cannot use Map interface for creating a map. We must use a class (like HashMap, TreeMap, etc.).
      This means the following two ways of instantiating a Map are correct:
      Map myMap = new HashMap();
      Map myMap2 = new TreeMap();
      Also, the following way of instantiating a HashMap is syntactically correct:
      HashMap myMap3 = new HashMap();
      Again, the following way of instantiating a TreeMap is syntactically correct:
      TreeMap myMap4 = new TreeMap();
      But the following three ways are wrong:
      Map myMap5 = new Map();
      HashMap myMap6 = new Map();
      TreeMap myMap7 = new Map();
      This is because we cannot create a "new Map()" since Map is an interface and not a class.

  • @DirectNRG
    @DirectNRG 2 роки тому

    never subscribed that fast in my life...Straight to the point, easy to understand. keep it up!

  • @Lightburg-hm1vj
    @Lightburg-hm1vj 3 місяці тому +1

    Great video, please recommand this guy youtube

  • @miler_2260
    @miler_2260 2 роки тому +3

    This is absolutely amazing! Your explanations are so clear and straight to the point... You have got a very special skill there my friend, good work!!

  • @pandadoskoi
    @pandadoskoi Рік тому

    Thank you so much. I certainly had my struggles to understand what Maps in Java are and what their purpose is, my scripts from university read like messages from outer space... but now I at least have a clue to get further in learning. I felt so stuck with this topic and felt so stupid because everyone said "oh, maps and hashmaps are so easy". Again, thank you effin much. Left a like and sub! :)

  • @faroukmatamir
    @faroukmatamir 2 роки тому +1

    Really big thanks to you for your efforts, I really understand the topic when I watch you.
    Please hange on and you will reach a million sub soon

  • @whiteliszt8805
    @whiteliszt8805 3 роки тому +3

    Tnx a lot for ur videos, i really enjoy how u represent the agenda and especially ur english

  • @jvsnyc
    @jvsnyc 3 роки тому +20

    This video, like pretty much all of yours, is awesome. I would avoid calling it a Full Tutorial maybe, despite the fact that it is well self-contained, because there are important things like the .hashCode() / .equals() contract, and warnings about not using mutable objects as keys that are ultimately Very Important to know which aren't addressed in this video. That totally leaves aside things about how the internals work, because you could know all the rules for safely and effectively using them without understanding the internals, but probably not vice versa. It is a great Introduction to all the basics, however.

  • @RolandMurdoc
    @RolandMurdoc Рік тому

    I love the way you explain Java Subjects, you make me feel like it is not really that hard.

  • @simbarashemaunga5575
    @simbarashemaunga5575 5 місяців тому

    The Java content delivery here is just top notch!

  • @halejandro8753
    @halejandro8753 3 роки тому +3

    Learn JAVA and English... It's great... Voy a ser sincero, aunque no se mucho ingles, puedo entender la gran mayoría de lo que estas ilustrando. Excelente forma de explicar...

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому

      Gracias! I'm very glad my videos could help in ways I didn't even expect!

  • @legendarybond4779
    @legendarybond4779 11 місяців тому

    I stumbled across some of your youtube videos as I wanted to understand more of Java. Thanks alot for these uploads!

  • @davishek7
    @davishek7 2 роки тому +2

    Hope text books had this type of explanation. Great videos John. Refreshing my Java knowledge after 2 years of not using it.

  • @sigfigronath
    @sigfigronath 2 роки тому +2

    This is so simple wow, thanks John!

  • @cyrilmartin9221
    @cyrilmartin9221 3 місяці тому

    Concept is crystal clear now. Thank you!!

  • @yuemingpang3161
    @yuemingpang3161 2 роки тому +2

    Hi John, I really like your channel and I just subscribed! I have one comment after watching your video (please correct me if I am wrong). There is a very important property of the HashMap: a value can have multiple keys but one key can only refer to one value at a time. And that's why we can only get a value form key(s). We can know if a value exists but we cannot get the keys from a value (this also violates the designing purpose of the HashMap).

  • @jakingsarchly6433
    @jakingsarchly6433 Рік тому

    Couldn't ask for a better teacher @ John. Thank you!

  • @ohmarianito4617
    @ohmarianito4617 3 роки тому +4

    Very good videos, I am already watching many of them, you explain very well, I hope your motivation continues! +1 follower

  • @jyotvkathalu7901
    @jyotvkathalu7901 Рік тому

    It’s a very crisp and detailed explanation… i was waiting for you to explain iterating maps … thq for video

  • @calabert
    @calabert 5 місяців тому

    I want to truly thank you. You're helping me a lot. Your way to explain things is clear and to the point. Very easy to catch tricky concepts with your tutorials. Thanks! new sub :)

  • @TheStormtrooperrr
    @TheStormtrooperrr Рік тому

    Clear, no BS, concise. Just subbed

  • @BronkoBanane
    @BronkoBanane 2 роки тому +2

    straightforward, structured and contains the essentials. Thanks for this good video!

  • @abigailmengesha4448
    @abigailmengesha4448 Рік тому

    This man is an icon. I didn’t fully understand until I watched his video

  • @farhadhabibullah548
    @farhadhabibullah548 2 роки тому

    clean, straightforward.
    If you are still confused about HashMap after watching this video then Java is not for you mate.

  • @liljj2k10
    @liljj2k10 2 роки тому

    The best explanation I ever came across

  • @vijivenkat9414
    @vijivenkat9414 2 роки тому

    I just subscribed to the channel just watching one video, so specific, clear concise..keep rocking..

  • @PrajwalYP2001
    @PrajwalYP2001 Рік тому

    I like the way of simplicity in explaining the HashMap topic. 👍

  • @qusaiclasher4452
    @qusaiclasher4452 10 місяців тому

    You're the best. Your teaching is way better than my professor. Please keep uploading more useful videos like this one

  • @ncrose99
    @ncrose99 11 місяців тому +1

    thank you for giving me a chuckle at the song reference 😁

  • @TheCurious36
    @TheCurious36 Рік тому

    coding with john. you are a good man. thank you.

  • @HatTrick4030
    @HatTrick4030 Рік тому

    Amazing!! understood HashMaps within 5 minutes 😎. Super Thanks

  • @hey4077
    @hey4077 Рік тому

    Thank you very much, I appreciate your videos and the fact that they're for free!

  • @ismoilova_shahina
    @ismoilova_shahina 2 роки тому +1

    thanks John for this well-explained tutuorial

  • @Garrison86
    @Garrison86 2 роки тому +1

    Awesome! This is Clear and easy to understand

  • @clingyking2774
    @clingyking2774 Рік тому

    This guy makes Java seems so easy.

  • @sweetshoez
    @sweetshoez Рік тому

    quality! thanks for getting to the point. coming from javascript, python, and ruby it was insane to me that you can't just make a key/value pair "object" just using curly braces and half a line of code

  • @Kofogt
    @Kofogt 2 роки тому

    I am obsessed with your videos

  • @Devivl
    @Devivl Рік тому

    One of the best. Short and clear. Thank you, John!

  • @desicow493
    @desicow493 2 роки тому

    I'm glad UA-cam recommended me this channel!

  • @randomcommentor
    @randomcommentor 2 роки тому

    YESSS
    My life was in shambles after learning you couldn't make associative arrays in java... These maps will do. Thank you.

  • @jyotibansode5067
    @jyotibansode5067 2 роки тому +1

    Hey John, thanks for the videos short and well explained, more forward to see ur videos on Spring Boot, Microservices, RestAPI........

  • @rafaelcruz8966
    @rafaelcruz8966 Рік тому

    Seriously helping me get back in the groove for advanced data structures thank you 🙏🏽

  • @idunsky
    @idunsky Рік тому

    hey John, thanks for your videos, they're super helpfull it took you 10 minutes to explain a three hours lecture

  • @rajesh_gottimukkula
    @rajesh_gottimukkula 2 роки тому

    Thank you John for such crisp and clear explanation.

  • @zehrairkicatal2156
    @zehrairkicatal2156 3 роки тому +2

    How you do this , This is perfectly summarised Map and HashMap I have ever watched 🤩

  • @robelso5646
    @robelso5646 3 роки тому +3

    Incredible video! subscribed

  • @michal1798
    @michal1798 Рік тому

    You make the best java toutorials on youtube imo👍

  • @gird4p
    @gird4p Місяць тому

    You made my day with this simple explanation. Thanks!

  • @nzubehenry445
    @nzubehenry445 2 роки тому

    you are so good at explaining things

  • @GiosBordoli
    @GiosBordoli 7 місяців тому

    This is exactly the video I was looking for! Thank you!

  • @dost27
    @dost27 2 роки тому

    Very simple and easy to understand the concept of Map. Keep it up

  • @everythingabout3479
    @everythingabout3479 8 місяців тому

    Very nice channel . Actually clears the confusion

  • @gideonob
    @gideonob 2 роки тому

    Best video I've watched on any Java data structure! Thank you sir!

  • @karthikm5507
    @karthikm5507 2 роки тому

    Crisp and clear. Really liked the way you explained.

  • @ziekaman2450
    @ziekaman2450 2 роки тому +1

    Very well explained. 10/10

  • @Quantum_in_Java
    @Quantum_in_Java 2 роки тому

    I am super glad that I discovered this channel .
    Your videos are precise, to the point and very easy to understand (especially you way of explaining ) .
    Thanks a lot sir. Saviour of semester exams. 👍🏻

  • @ayushsaxena3511
    @ayushsaxena3511 2 роки тому

    It's absolutely brilliant to watch your videos.. Loved the way you present things with such a simpler approach..

  • @glenn8781
    @glenn8781 2 роки тому

    Brooo.. I love you so much! You bring a new, exciting and deeper understanding to Java. You have a unique ability to put things in a really interesting way! Looking forward to seeing more videos from you on Java concepts. Your channel will surely grow exponentially!

  • @MinKiu410
    @MinKiu410 2 роки тому

    Randomly appearing on my recommendation. Though I actually learnt Java before, this video is quite nice represented. You got my sub + like

  • @wucsci9420
    @wucsci9420 Рік тому +1

    I have to implement several HashMaps for a project due in 6 days and I was freaking out because HashMap sounds like a complicated word and I don't know what the heck they are! After watching your video I realized that HashMap is just a synonym for Dictionary. LMAO! The relief I'm experiencing right now, it's going to make me procrastinate for another 4 days at least.

  • @idreesalao6155
    @idreesalao6155 2 роки тому +1

    This was very helpful and easy to understand. I really appreciate it, thanks.

  • @mrblob5413
    @mrblob5413 2 роки тому +7

    A LinkedHashMap retains insertion order, and a TreeMap sorts by keys.

  • @jack.eastman
    @jack.eastman 2 роки тому +1

    As a software developer who writes java every day, my mind was blown when you said you can just print out a HashMap. I've always assumed HashMaps were like Lists and would just print the object ID.

    • @CodingWithJohn
      @CodingWithJohn  2 роки тому +1

      If it's been a while, I think you should try it with a List too and see what happens 🙂

    • @jack.eastman
      @jack.eastman 2 роки тому

      @@CodingWithJohn Amazing! Thank you 😂