#22 - What is HashSet in Collection Framework || Important features of HashSet in Java

Поділитися
Вставка
  • Опубліковано 24 січ 2025

КОМЕНТАРІ •

  • @aviet90
    @aviet90 4 роки тому +5

    Thanks Naveen for the explanation. If somebody is wondering why the hash set displays the integers in sorted order then that's because hash set uses hash map internally and hash map stores the elements in a hash table. Since we are adding integers it uses integers hash code which returns an integer. So if you add integers they are added as per sorted order. However if you try adding double values then you would see a rather different output as the hash code computation here is slightly different.
    Set st = new HashSet();
    st.add(2.4);
    st.add(1.4);
    st.add(3.4);
    st.add(4.4);
    st.add(5.4);
    st.add(6.4);
    st.add(7.4);
    st.add(8.4);
    for (Double i : st) {
    System.out.println(i);}
    Output:-
    2.4
    1.4
    6.4
    7.4
    3.4
    4.4
    8.4
    5.4

  • @rukmanibabu897
    @rukmanibabu897 4 роки тому +6

    Thanks you . All video well explained. i have switched job after watching u r learning video .

  • @prikshitverma3885
    @prikshitverma3885 4 роки тому

    Thank you

  • @shaiksuleman3191
    @shaiksuleman3191 4 роки тому

    Hi Can you please make videos for front tools using java/jsp .May be it will help u so many resource to participate in events occurring in company so that there is no dependency on other teams

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

    When i add like this s.addAll(Arrays.asList(new int[] {3,5,6})); i am getting the below error:
    The method addAll(Collection

    • @maverick3867
      @maverick3867 6 місяців тому +1

      try new Integer[] instead of new int[] as Collection stores objects and not primitives

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

    In ur previous java collection series u taught us that hashset directly extends set interface and tree set extends sorted set and now I am confused between these two videos

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

      It's an advanced series. Refer the latest one

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

      @@naveenautomationlabs in latest one also... Hashset directly implementing set interface and tree set implementing sorted set