Map and HashMap in Java - Full Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 มิ.ย. 2021
  • Complete Java course: codingwithjohn.thinkific.com/...
    Maps and HashMaps in Java can be so confusing when you're first starting out your Java career.
    But Maps and HashMaps don't have to be confusing at all! A Map is a simple, powerful tool to have in your programming arsenal, and this video will give you everything you need to know to use Map and HashMap confidently in Java, even if you're a Java beginner.
    Learn or improve your Java by watching it being coded live!
    Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletrial.com/johnclean...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com/donate/?hosted...
    ☕Complete Java course:
    codingwithjohn.thinkific.com/...
    codingwithjohn.com

ความคิดเห็น • 446

  • @gur151
    @gur151 3 ปีที่แล้ว +441

    Super underrated channel. With how little views your videos currently get, I'm surprised TH-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 ปีที่แล้ว +73

      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 ปีที่แล้ว +94

    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 ปีที่แล้ว +3

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

  • @yuto5636
    @yuto5636 3 ปีที่แล้ว +162

    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!

  • @shoaibaltaf705
    @shoaibaltaf705 3 ปีที่แล้ว +17

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

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +2

      Thanks for the words of encouragement and thanks for watching!

  • @peterswrath8806
    @peterswrath8806 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!

  • @CarlosCed
    @CarlosCed 11 หลายเดือนก่อน +5

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

  • @youthought878
    @youthought878 2 ปีที่แล้ว +24

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

  • @crookedcrowe9215
    @crookedcrowe9215 ปีที่แล้ว +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!!!!!

  • @dibjr
    @dibjr 2 ปีที่แล้ว +3

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

  • @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!!

  • @shahoodgmail
    @shahoodgmail 2 ปีที่แล้ว +26

    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! 👍🏼👍🏼

  • @DirectNRG
    @DirectNRG ปีที่แล้ว

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

  • @ChickensAndGardening
    @ChickensAndGardening 11 หลายเดือนก่อน

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

  • @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.

  • @Naruto_Uzumaki_
    @Naruto_Uzumaki_ 6 หลายเดือนก่อน

    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!!

  • @Devivl
    @Devivl ปีที่แล้ว

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

  • @mattmalan6
    @mattmalan6 2 ปีที่แล้ว +6

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

  • @BronkoBanane
    @BronkoBanane 2 ปีที่แล้ว +2

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

  • @IralaPraveen-ku6zr
    @IralaPraveen-ku6zr หลายเดือนก่อน

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

  • @aryanjoshi9703
    @aryanjoshi9703 4 หลายเดือนก่อน +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

  • @ceciliacastro3093
    @ceciliacastro3093 11 หลายเดือนก่อน

    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.

  • @BernardVisagie
    @BernardVisagie 2 ปีที่แล้ว +4

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

  • @legendarybond4779
    @legendarybond4779 7 หลายเดือนก่อน

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

  • @rafaelcruz8966
    @rafaelcruz8966 ปีที่แล้ว

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

  • @ayushsaxena3511
    @ayushsaxena3511 2 ปีที่แล้ว

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

  • @pedroaboffa
    @pedroaboffa 2 ปีที่แล้ว +4

    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!

    • @pedroaboffa
      @pedroaboffa 2 ปีที่แล้ว

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

  • @hassanlearning4086
    @hassanlearning4086 ปีที่แล้ว

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

  • @calabert
    @calabert หลายเดือนก่อน

    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 :)

  • @popularcoffee9141
    @popularcoffee9141 2 ปีที่แล้ว

    love the topics you discussed! they are what i would wonder but too lazy to dig in. big thank you to that! (and the clear explanation as well)

  • @venkat757
    @venkat757 2 ปีที่แล้ว +2

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

  • @flytoinfinityvivi
    @flytoinfinityvivi หลายเดือนก่อน

    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 (:

  • @MichaelPayPlus
    @MichaelPayPlus 2 ปีที่แล้ว +31

    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 ปีที่แล้ว +6

      @@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.

  • @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!

  • @user-lj9sq6lr5v
    @user-lj9sq6lr5v 7 หลายเดือนก่อน +1

    My man, I think you are the only one who explain this so easily to understand.

  • @jakedotnet
    @jakedotnet 2 ปีที่แล้ว +19

    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 ปีที่แล้ว +2

      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.

  • @RolandMurdoc
    @RolandMurdoc ปีที่แล้ว

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

  • @xiangyuliu9629
    @xiangyuliu9629 2 ปีที่แล้ว

    pretty clear, cut to the chase, love this video, subscribed already.

  • @jyotvkathalu7901
    @jyotvkathalu7901 ปีที่แล้ว

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

  • @szaryn
    @szaryn 2 ปีที่แล้ว

    Yo! Clear, straight-forward, and fun explanation. Thank you so much, John! ^^

  • @justinbanza4751
    @justinbanza4751 2 ปีที่แล้ว +2

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

  • @stevenschelling8452
    @stevenschelling8452 2 ปีที่แล้ว

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

  • @karthikm5507
    @karthikm5507 2 ปีที่แล้ว

    Crisp and clear. Really liked the way you explained.

  • @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. 👍🏻

  • @sigfigronath
    @sigfigronath 2 ปีที่แล้ว +2

    This is so simple wow, thanks John!

  • @rajesh_gottimukkula
    @rajesh_gottimukkula ปีที่แล้ว

    Thank you John for such crisp and clear explanation.

  • @mrblob5413
    @mrblob5413 2 ปีที่แล้ว +7

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

  • @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.

  • @saronabi1387
    @saronabi1387 ปีที่แล้ว

    U always make things easy for us , really am impressed with your courses, thank you so much for helping us!

  • @dsnewby
    @dsnewby ปีที่แล้ว

    Fantastic video and such a well put explanation, easy and fun to follow along. Thanks a lot!

  • @idreesalao6155
    @idreesalao6155 2 ปีที่แล้ว +1

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

  • @Rowa_n
    @Rowa_n 2 ปีที่แล้ว +1

    this is very helpful! thank you so much for making this tutorial! it was easy to follow

  • @GiosBordoli
    @GiosBordoli 3 หลายเดือนก่อน

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

  • @jakingsarchly6433
    @jakingsarchly6433 ปีที่แล้ว

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

  • @simbarashemaunga5575
    @simbarashemaunga5575 หลายเดือนก่อน

    The Java content delivery here is just top notch!

  • @godiloverock
    @godiloverock ปีที่แล้ว

    Helpful, and explanatory! Thanks for the video.

  • @ohmarianito4617
    @ohmarianito4617 2 ปีที่แล้ว +4

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

  • @vijivenkat9414
    @vijivenkat9414 ปีที่แล้ว

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

  • @twinklehingu2757
    @twinklehingu2757 2 ปีที่แล้ว +1

    This was very helpful and easy to understand. I really appreciate it, Thank you so much.

  • @pandadoskoi
    @pandadoskoi 8 หลายเดือนก่อน

    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! :)

  • @hey4077
    @hey4077 ปีที่แล้ว

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

  • @brilliantdecember
    @brilliantdecember ปีที่แล้ว

    Very well explained. Glad to have found your channel.

  • @Mynarski
    @Mynarski ปีที่แล้ว

    Straight forward and concise.

  • @TheDoomCompany
    @TheDoomCompany 7 หลายเดือนก่อน

    Thank you, this video answered my questions right away

  • @TheStormtrooperrr
    @TheStormtrooperrr 11 หลายเดือนก่อน

    Clear, no BS, concise. Just subbed

  • @Diana_13.
    @Diana_13. ปีที่แล้ว

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

  • @HatTrick4030
    @HatTrick4030 ปีที่แล้ว

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

  • @Garrison86
    @Garrison86 2 ปีที่แล้ว +1

    Awesome! This is Clear and easy to understand

  • @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!

  • @garrickreynolds2015
    @garrickreynolds2015 2 ปีที่แล้ว

    This is an amazing and clear explanation. Thank you!

  • @gideonob
    @gideonob 2 ปีที่แล้ว

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

  • @personontheinternet2164
    @personontheinternet2164 2 ปีที่แล้ว

    Really love the presentation and energy of this channel!

  • @CanopusInfinity
    @CanopusInfinity 2 ปีที่แล้ว

    Thank you for uploading such great content and educating us. Your explanation is so precise and concise.

  • @evanpilling8429
    @evanpilling8429 11 หลายเดือนก่อน

    This is such an awesome channel. Thanks for the video!

  • @faroukmatamir
    @faroukmatamir ปีที่แล้ว +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

  • @jacobmockler
    @jacobmockler 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

  • @jesusbrito699
    @jesusbrito699 ปีที่แล้ว

    Hi John!! your video are awesome!! you help me allways, thanks for this.
    Argentina

  • @nethmiwijebandara3315
    @nethmiwijebandara3315 ปีที่แล้ว

    Thank you. Well explained!

  • @whiteliszt8805
    @whiteliszt8805 3 ปีที่แล้ว +3

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

  • @PrajwalYP2001
    @PrajwalYP2001 9 หลายเดือนก่อน

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

  • @everythingabout3479
    @everythingabout3479 4 หลายเดือนก่อน

    Very nice channel . Actually clears the confusion

  • @ForrestTaft101
    @ForrestTaft101 2 ปีที่แล้ว

    Brilliantly simple and concise. Subscribed

  • @nerodant85
    @nerodant85 ปีที่แล้ว

    Thank you for making it easy to understand

  • @sweetshoez
    @sweetshoez 11 หลายเดือนก่อน

    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

  • @TheCurious36
    @TheCurious36 ปีที่แล้ว

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

  • @taldennis8058
    @taldennis8058 2 ปีที่แล้ว

    Excellent video as always, thank you very much John you are the best!!

  • @andrewchen861
    @andrewchen861 ปีที่แล้ว

    Thank you for the video! :) It was helpful.

  • @ahmetalperenyildirim6184
    @ahmetalperenyildirim6184 ปีที่แล้ว

    Great content! sharp clear, thank you for sharing, you teaching us a lot!

  • @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........

  • @Moon-Knight313
    @Moon-Knight313 2 ปีที่แล้ว

    Awesome explanation! Thanks John! Keep going!👍

  • @dost27
    @dost27 ปีที่แล้ว

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

  • @qusaiclasher4452
    @qusaiclasher4452 6 หลายเดือนก่อน

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

  • @robelso5646
    @robelso5646 2 ปีที่แล้ว +3

    Incredible video! subscribed

  • @desicow493
    @desicow493 2 ปีที่แล้ว

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

  • @TheJoannathon
    @TheJoannathon ปีที่แล้ว

    Thank you for explaining it so well!

  • @Lamitoon
    @Lamitoon 5 หลายเดือนก่อน

    this video helped a lot! Ty ☺

  • @justinbanza4079
    @justinbanza4079 2 ปีที่แล้ว

    Thank you John,
    Very clear

  • @michal1798
    @michal1798 8 หลายเดือนก่อน

    You make the best java toutorials on youtube imo👍

  • @ismoilova_shahina
    @ismoilova_shahina ปีที่แล้ว +1

    thanks John for this well-explained tutuorial

  • @btmahvash
    @btmahvash ปีที่แล้ว

    Excellent, I learned very well

  • @evgenystep8897
    @evgenystep8897 8 หลายเดือนก่อน

    Super easy explanation thx to clear out how to easily use HashMaps!