HashSet In Java Tutorial #52

Поделиться
HTML-код
  • Опубликовано: 2 фев 2025
  • $1,000 OFF ANY Springboard Tech Bootcamps with my code ALEXLEE. See if you qualify for the JOB GUARANTEE! 👉 bit.ly/3HX970h
    The HashSet in Java can be tricky at first. In this video I show you how you use the HashSet in Java! ✅Hopefully, what I've taught you will help you fix your HashSet Java code.
    👑Start practicing now with 10 free java programs - alexlorenlee.com/
    🐙 Source Code - github.com/ale...
    Here are some useful HashSet Java methods:
    hashset.add();
    hashset.clear();
    hashset.contains();
    hashset.remove();
    hashset.isEmpty();
    hashset.iterator();
    The HashSet in java code can be tricky at first... But SURELY you'll get it :) If you followed along, congrats! You learned-by-doing!
    I hope you enjoyed this HashSet in Java tutorial! I like to have a nice mix of java tutorials and actual java programs for you all :)
    Do you want to learn how to write java code from scratch, in Java? Check out my Java Tutorial For Beginners: • Coding For Beginners I...
    Was this able to fix your Java Hashset code?
    Full Java Tutorial For Beginners Playlist: • Full Java Course by Al...
    Free Tips: bit.ly/3U6HXcb
    Disclosure: The Springboard link provided is linked to my affiliate account & supports the channel.
    ~
    Alex Lee

Комментарии • 136

  • @alexlorenlee
    @alexlorenlee  Год назад +1

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

  • @wewonbro1620
    @wewonbro1620 3 года назад +42

    Programming can be hard to learn by just reading. If only you knew how much and how fast I learn from your videos. I won't forget you when I make it to google.

  • @xxFivestarfreakxx
    @xxFivestarfreakxx 4 года назад +41

    dog.... i subscribed as soon as i seen the class name HashBrowns

  • @voidincognito4319
    @voidincognito4319 4 года назад +18

    Comment to show gratitude towards this whole channel...
    Hope you reach 1 mill subs soon!

  • @ilyasilyas6252
    @ilyasilyas6252 2 года назад

    Broooooo I remember when you only had 100 views literally not to long ago lol!! You came a long way bro! Congrats

  • @heayyyyyyy11
    @heayyyyyyy11 4 года назад +2

    Thank you. Now i get it what my teacher can't tell me :D

  • @sofiasik8251
    @sofiasik8251 3 года назад

    "It's hashed all around so that's why it's called a hashSet" Gold. Good video! Thank you.

    • @sandy-gx8zp
      @sandy-gx8zp 16 дней назад

      It is not Hashed, it was sum of alll numbers

  • @rochdimaria
    @rochdimaria 4 года назад +1

    man you are the God of Java

  • @Sofien_Steve
    @Sofien_Steve 2 года назад

    The best java teacher on youtube

  • @rittenbrake1613
    @rittenbrake1613 4 года назад +8

    10:10 it is not a random number 42, is the sum of all the value ( 13 +24 +5 =42) , dunno what's mean by your "disperse" ,maybe we are talking about the same thing

    • @erlendor3332
      @erlendor3332 3 года назад

      That's true. But if you make a HashSet then the hashCode() will return a number once again. For example if the HashSet contains [a, b, c] then the hashCode(); returns 294

  • @mu-rad
    @mu-rad 5 лет назад +4

    Your videos are great!
    Thanks!!

  • @arsenengenzi7852
    @arsenengenzi7852 4 года назад +4

    My man said "RIP Harambe" and I'm here for it 😂😂😂😂😂

  • @camm7766
    @camm7766 4 года назад +1

    This is an amazing channel

  • @p2p2p2p2p2p
    @p2p2p2p2p2p 5 лет назад +9

    Your videos are so useful! Can you make separate tutorial on Stringbuilder?

  • @johnfrog9210
    @johnfrog9210 5 лет назад +7

    Thankyou for your videos, Why would you use a hashset and not an array to print out each value?

    • @deadpl55
      @deadpl55 3 года назад

      Plz tag me of someone answer

    • @AndrewSu180
      @AndrewSu180 3 года назад +2

      Hashsets do not allow duplicate data, that is probably the main reason to use a hashset over an array.

  • @Vithal_Nivargi
    @Vithal_Nivargi 3 года назад

    Nice explained sir thankyou

  • @adireusch4522
    @adireusch4522 4 года назад

    Dude! You’re AMAZING!!!!!

  • @kakashi99908
    @kakashi99908 2 года назад +1

    What is the reason to use an iterator instead of a normal loop?

  • @chandureddy5208
    @chandureddy5208 4 года назад +1

    Good explanation, Thank you!

  • @jonathanjordan21
    @jonathanjordan21 4 года назад +4

    10:10
    doesnt that the sum of the values??
    13 + 24 + 5 = 42

  • @aryankushwaha9306
    @aryankushwaha9306 10 месяцев назад

    can you plz tell us what are the difference btw the array list, HashSet, linked list, and array deque????

  • @yeargun5582
    @yeargun5582 4 года назад +2

    HOOOOOOLY. That's strange 8:15 . Cause like, 24 is my favourite number aswell and i legit tell the same reason why i like that number ( Cause its divisible with a lot of numbers ). mhmh just wanted to share :)

  • @maanialhdrami1187
    @maanialhdrami1187 2 года назад

    Thank you so much, you really helped me

  • @hafezpirzadeh2380
    @hafezpirzadeh2380 5 лет назад +1

    Great video!

  • @shashikanth-v9k
    @shashikanth-v9k 2 года назад

    Iterator is it wrong?

  • @BlazinPass
    @BlazinPass 4 года назад +4

    Congrats. You just fully replaced my professor. I should be paying you my tuition!

  • @GoodTimeDev
    @GoodTimeDev 4 года назад

    Quality stuff dude

  • @Himanshu-xm8cw
    @Himanshu-xm8cw 4 года назад

    This was really helpful 🖖

  • @huyn6977
    @huyn6977 3 года назад +2

    Hi Alex! first of all thank you very much!
    My question to you is what are the difrences between a Hashmap and a Hashset?

    • @anujkumarpatel2686
      @anujkumarpatel2686 3 года назад +5

      HashSet is a set, e.g. {1,2,3,4,5}
      HashMap is a key -> value (key to value) map, e.g. {a -> 1, b -> 2, c -> 2, d -> 1}

    • @huyn6977
      @huyn6977 3 года назад +1

      @@anujkumarpatel2686 thank you !

    • @nirmeenshamma1839
      @nirmeenshamma1839 3 года назад +1

      @@anujkumarpatel2686 Good explanation, Thank you!

  • @rukna3775
    @rukna3775 5 лет назад +13

    Then what's the difference between hashset and arraylist

    • @1komentator
      @1komentator 5 лет назад +11

      Hashset doesn't accept duplicates, while arraylist do

    • @tomasjaron6869
      @tomasjaron6869 4 года назад +2

      Also you can't get let's say the 1. element from a hashset.

  • @joethompson8147
    @joethompson8147 4 года назад

    986 likes! Lets go people :) Great video Alex

  • @LizyAd
    @LizyAd 4 месяца назад

    Thanks so much!

  • @rittenbrake1613
    @rittenbrake1613 4 года назад +1

    9:49 you are lovely for the your hand gesture

    • @anwarulbashirshuaib5673
      @anwarulbashirshuaib5673 4 года назад

      He could've admitted that he didn't know much about HashSets. The way he explained HashSets is not expected from a youtuber who uploads content to educate viewers

  • @Hizbullla
    @Hizbullla 5 лет назад +6

    Considering that this is a fairly new channel, I hope I can get this message across to you...
    What you are doing is great, your delivery is clear and concise, and in that regard, would it be possible to hold our hands through a relatively (to someone who had gone through the basic syntax) complex Java application, preferably a desktop with SQL queries and proper Swing usage?
    A lot of the code on RUclips is pretty much the onscreen creating of the source code with little to no explanation as to why we use what we just used, and it was be a massive help if you can make something similar giving us your logic and reasoning behind the work.

  • @Deepika-hm4br
    @Deepika-hm4br 3 года назад

    seems like a hashset is basically an appendable array that doesn’t allow for duplicates. are there any other benefits to using a hashset over an array

  • @nanug6292
    @nanug6292 4 года назад

    Thanks it helped a lot

  • @user-4538
    @user-4538 2 года назад

    Does anybody know how I can get that same list of options at 3:16 to appear in blueJ when I use classes from the java-library? That way I wouldn't have to go to their website everytime I want to explore the different methods of a java-library class? Is that possible to do in blueJ?

  • @keenang09
    @keenang09 3 года назад +1

    If at all possible... a video on HashTables or maybe just a video illustrating the differences between types of Hashing

  • @maheshn6933
    @maheshn6933 2 года назад

    when you use hashcode, the result is sum of all number in the HashBrowns, is it something to be considered?

  • @kwakukusi4094
    @kwakukusi4094 3 года назад

    does hashset allow duplicate values ?

  • @fridomaraya7438
    @fridomaraya7438 3 года назад

    so helpful but ,what is the difference with the Array List?

  • @iamarpit.
    @iamarpit. Год назад

    it is showning red line under integer and saying that integer cannot resolved into a type pls suggest me what can i do......

  • @deb5976
    @deb5976 2 года назад

    HashSet implements the set interface, that is one of the two main interfaces in the java collection.. There are a lot of things to learn about this hashSet object..

  • @venusisalwaysabove
    @venusisalwaysabove 4 года назад +1

    write "sout" then CTRL+SPACE as a short cut for ''System.out.println()"

    • @rittenbrake1613
      @rittenbrake1613 4 года назад +3

      it's weird , some of his videos he did , some he didn't , maybe he is afraid of confusing people

    • @venusisalwaysabove
      @venusisalwaysabove 4 года назад +1

      @@rittenbrake1613 true,
      for me i was just trying to give it as a hint to others.

    • @rittenbrake1613
      @rittenbrake1613 4 года назад

      @@venusisalwaysabove yes sure ! It helps a lot , when I was a beginner , I dunno this shortcut too

    • @rittenbrake1613
      @rittenbrake1613 4 года назад +2

      @@venusisalwaysabove yes sure ! Thank you Ayoub ! It helps a lot , when I was a beginner , I dunno this shortcut too

    • @sneakycheeky531
      @sneakycheeky531 4 года назад

      sout tab

  • @debasishsahu1556
    @debasishsahu1556 2 года назад

    Can we use (for each loop) in HasSet Just like You used While ?

  • @guieltorres
    @guieltorres 3 года назад

    I have a hashset witch contains a Custom Object added. Example:
    private static Set people= new HashSet();
    How can i create a function to retrieve a specific People to the hashset witch pass a People name?
    Ex:
    public People checkName(String name) {
    return // RETURN THE PEOPLE OF THE HASH CONTAINS name passed
    }
    please help me

  • @vishy
    @vishy 5 лет назад +1

    Alex, please can you tell me the music you used at the end of the video?

  • @kitty_kee
    @kitty_kee 4 года назад +1

    i like your IDE. Which is you using. Kindly tell me or paste link here so i can download

    • @sneakycheeky531
      @sneakycheeky531 4 года назад

      www.tomorrowtides.com/ictjournaldevfixed.html

    • @kitty_kee
      @kitty_kee 4 года назад

      @@sneakycheeky531 this link is dancing 💃

    • @sneakycheeky531
      @sneakycheeky531 4 года назад

      @@kitty_kee he's using eclipse. most software have there name at the top .

    • @kitty_kee
      @kitty_kee 4 года назад

      @@sneakycheeky531 exactly! 😎 now I have netBean IDE that is better than eclipse and parallel to Android Studio for making mobile apps. I recommend you to use netBeans.

    • @sneakycheeky531
      @sneakycheeky531 4 года назад

      @@kitty_kee im already using it. add me on discord disco#9740

  • @yicai7
    @yicai7 4 года назад

    Thanks dude!

  • @abdeselamselami4532
    @abdeselamselami4532 5 лет назад +1

    Thanks a lot

  • @curesnow6493
    @curesnow6493 4 года назад

    Can you do hash table and priority queue?

  • @floraposteschild4184
    @floraposteschild4184 4 года назад +1

    For Integers, anyway, the hashcode is the total of the numbers you put in.

  • @caydaruuskayse4643
    @caydaruuskayse4643 6 месяцев назад

    Thanks sir

  • @ferfykins
    @ferfykins 4 года назад +1

    Excellent video, thanks!! I was wondering if you can have multiple types in parameter of hashset? for example: HashSet hashbrowns = new HashSet();
    and if this is possible, how would the iterator handle multiple types? Thanks

    • @John-zs3jz
      @John-zs3jz 4 года назад +3

      I don't think you can have more than 1 data type parameter for HashSet, only for HashMap where there is a key and a value.

  • @aleksamarinkovic4363
    @aleksamarinkovic4363 5 лет назад +1

    What is the difference between Hashset and Stringbuilder?

    • @aleksamarinkovic4363
      @aleksamarinkovic4363 4 года назад

      Stringbuilder is only for strings I guess but I think there is more to it

  • @johnalsanamai-kurut338
    @johnalsanamai-kurut338 4 года назад +1

    what are the differences of hash-set and tree-set ?

    • @Rob-J-BJJ
      @Rob-J-BJJ Год назад

      the ordering is different tree-sets have natural ordering.

  • @kvelez
    @kvelez Год назад

    Very useful.

  • @kajulooriraghu821
    @kajulooriraghu821 6 месяцев назад

    Awesome videos

  • @EpicphoneGamer
    @EpicphoneGamer 3 года назад

    When do I use HashSets when programming in the field? What's the benefit?

  • @nikolaykolev89
    @nikolaykolev89 4 года назад

    Amazing!

  • @anelemadonda6191
    @anelemadonda6191 4 года назад

    I liked the video as soon as he said RIP HArambe

  • @medoncho2397
    @medoncho2397 2 года назад

    Can somebody enlighten me, when are hash sets a good choice instead of other data structures?

  • @MJforall
    @MJforall 2 года назад +1

    Why are you not uploading video related Java

  • @aye.myatmon4485
    @aye.myatmon4485 Год назад

    In HashSet , outputs are random why?

  • @amitsarker9768
    @amitsarker9768 4 года назад

    Please consider describing the time complexity also.

  • @anwarulbashirshuaib5673
    @anwarulbashirshuaib5673 4 года назад

    Alex, please don't confuse your viewers with things that you don't know. The way you explained HashSets at 9:48 freaked me out. I hope you will upload content that you really know about and give the viewers a better understanding. Cheers 😁😁

  • @addayounes3950
    @addayounes3950 4 года назад

    what's the common uses of HashSet ? and why we need it when we have arrays and ArrayList ?

    • @Theuser2022
      @Theuser2022 3 года назад +1

      Hashsets are not index-based, they take the values inside the list randomly ~ I think they're used to generate random values (like unique keys). And are faster that Arraylist for searching the list.

  • @BIKE486
    @BIKE486 4 года назад

    What's the difference between hashSet and arrayList?

  • @Ivan-ek6kg
    @Ivan-ek6kg 4 года назад

    what is the difference between Set set = new HashSet(); and HashSet set = new HashSet();

    • @anupriya1661
      @anupriya1661 4 года назад

      Hashset is a member of the collection set, so the object declared can be of both type, hashset or set, output will be same. Similar case with List list= new ArrayLIst() and List list= new LIst(), as arraylist is a member of collection List

    • @Ivan-ek6kg
      @Ivan-ek6kg 4 года назад

      @@anupriya1661 thx

    • @erikrl2
      @erikrl2 3 года назад

      @@anupriya1661 you cannot instantiate List as it's an interface.

  • @jacke2678
    @jacke2678 3 года назад +1

    You could have explained the difference between a set and a list, they look very similar to me.

  • @AashrayNarangBCE
    @AashrayNarangBCE 3 года назад

    its really hard to see whats on the screen what you cant take your eyes off the bottom right corner.

  • @RobertGuilman
    @RobertGuilman 4 года назад

    Hmmm, what's the difference between HashSet and an ArrayList, apart from the name, it function almost the same with ArrayList... At least from the example you give

  • @reezyyy8800
    @reezyyy8800 4 года назад +1

    Can anybody tell me what's exactly the difference between a HashMap and a HashSet?

    • @venusisalwaysabove
      @venusisalwaysabove 4 года назад +7

      first of all, HashMap implements Map interface, but the HashSet implements Set interface.Beside that, the HashMap work with key and value; it cannot have duplicate keys (but it can have duplicate values). and it use Put() as the inserting method.
      HashSet, cannot have duplicate value . It use Add() as the inserting method . and its slower than HashMap.

    • @John-zs3jz
      @John-zs3jz 4 года назад

      @@venusisalwaysabove Also HashSet can only have 1 data type parameter, while HashMap can have 2.

  • @WinterPhoenixForestKirin
    @WinterPhoenixForestKirin 2 года назад +1

    Great Harambe meme 👌
    Rest in Power, Harambe ✊😤🤭

  • @En3rGyFaNforEv3r
    @En3rGyFaNforEv3r 4 года назад

    why dont you just use arrayList for everything?

  • @jaypatil9338
    @jaypatil9338 4 года назад

    Why 5 is printed..? Bt not 3 or 1

  • @maazking9087
    @maazking9087 5 лет назад +1

    hey thanks for explaining things so magically ..i have a question....its pretty much the same as a hashMap...then whats the difference.

    • @tarunmathur7797
      @tarunmathur7797 5 лет назад +2

      HashMap also contains a key for its values

  • @arslanmehmood6371
    @arslanmehmood6371 4 года назад +2

    from now on i will call as alligators , diamonds are boring.

  • @navjotsingh2457
    @navjotsingh2457 2 года назад

    tysm

  • @popflazh
    @popflazh 4 года назад

    10:11 I dont really understand what he meant by that. Can somebody explain?

    • @popflazh
      @popflazh 4 года назад

      Or wait.. is it the sum of all values?

  • @nawaraskc5610
    @nawaraskc5610 4 года назад

    Iterator is so confusing ....can someone help..??

  • @keeprunning5457
    @keeprunning5457 Год назад

    gracias otra vez

  • @anwarulbashirshuaib5673
    @anwarulbashirshuaib5673 4 года назад +2

    9:48 If you are coming here to know why we call it HashSet then here's your answer 🤣😁

  • @daenzo3682
    @daenzo3682 4 года назад

    Good video, but flashing the patreon advertising with sound all 10 s is annoying. Doing this at the end of the video is better.

  • @dr_ejahn
    @dr_ejahn Год назад

    bro realy said rip harambe hahhahahahhahaha

  • @SatyamGupta-yq1pt
    @SatyamGupta-yq1pt 2 года назад

    op bro

  • @mmahal
    @mmahal 3 года назад +2

    like for Harambe

  • @abhijitvetal576
    @abhijitvetal576 4 года назад

    learning with background music is fun pls do this for whole video

  • @AliJardz
    @AliJardz 2 года назад

    Still giggling at harambe memes in 2023

  • @tfh5575
    @tfh5575 5 лет назад +1

    why am i so stupid ugh

  • @friedchicken5227
    @friedchicken5227 4 года назад

    Thanks for flexing ur Mac :(

  • @kevinfeng6700
    @kevinfeng6700 4 года назад

    "orangatang"

  • @schajuli1991
    @schajuli1991 3 года назад

    Orangatang? Really that's the way how you spell it in english? :D

  • @iliasvenianakis4523
    @iliasvenianakis4523 3 года назад

    You show how to use but you didnt explained why we should prefer it or what exactly it does .
    God bless the deslike button that can not show anymore.

  • @anth7rax
    @anth7rax 3 года назад

    orangatang......................................

  • @sxmvp
    @sxmvp 3 года назад

    orangatang

  • @YokoYokoOneTwo
    @YokoYokoOneTwo 4 года назад

    useless video you should show the difference between arraylist and hashset instead of typing same code in each video

  • @Arrathix
    @Arrathix 4 года назад

    I get wanting to push your website and subscribe/like, etc, but those sound effects are so irritating and distracting that I'll probably never watch another one of your videos despite the good content. Seriously, don't ruin your product for the sake of advertising Alex; you already ask for support at the start of the video, don't go overboard.

  • @jonathanjordan21
    @jonathanjordan21 4 года назад +2

    What is the difference between Hashset and ArrayList?