Intermediate Java Tutorial – 16 – HashSet

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

22 responses to “Intermediate Java Tutorial – 16 – HashSet”

  1. ravi teja Avatar

    Can't we convert Array to Set? instead converting Array to List and then list to Set.

  2. Bilal Ahmed Avatar

    Send BOB and Vegena 😉

  3. Patrascu Lucian Avatar

    – The HashSet subclass (from superclass Set) rearranges every element
    – The LinkedHashSet subclass links with the elements and won't rearrange them

  4. Aman Jain Avatar

    it doesn't remove three of a same kind!

  5. Zoro Ale Avatar

    SHtring ;)))))

  6. Michael Bucceri Avatar

    Hmm, when I typed in Set<String> set = new HashSet<String>(list);

    it is telling me that the type HashSet is not generic; it cannot be parameterized with arguments <String>

    Any advice on what I can do to fix this issue???

  7. Loizos Vasileiou Avatar

    what about if you want to replace the 2nd bob with a new element.???
    for example

    Output : [apple, bob, ham, tomato, bacon]

  8. JosephBingheim Avatar

    Could I overwrite the current list?
    Like instead of doing:
    Set<String> set = new HashSet<String>(list);
    Could I do:
    list = new HashSet<String>(list);

  9. Evgeni Kuzmov Avatar

    so, HashSet is an object, not a method?

  10. Devin M Avatar

    does the hashset randomly compile the lists elements? like instead of the lists original order, the set displays the elements in the wrong order

  11. Damir Huselja Avatar

    Hello Bucky,
    my issue: the program removes the first instance of bob not the second :/

  12. Harith Perera Avatar

    Bucky these data Structures are kinda hard to understand without illustrating…

  13. Jeremy Chen Avatar

    import java.util.*;

    public class julian {
        public static void main(String[] args) {

           String[] things = {"apple", "bob", "ham", "bob", "bacon"};
            List<String> list = Arrays.asList(things);

            System.out.printf("%s ", list);
            System.out.println();

            Set<String> set = new HashSet<String>(list);
            System.out.printf("%s ", set);
        }
    }

  14. Sou Dutta Avatar

    how the set is automatically getting rearranged in a typical manner
    ?

  15. 6BuSh Avatar

    Can someone please explain me what's the difference in constructing the hashset object as:
    HashSet<String> set = new HashSet<String>(list)
    instead of
    Set<String> set = new HashSet<String>(list) as shown in the tutorial?

  16. Sina Madani Avatar

    Seems useful. Nice tutorial

  17. Gates Wang Avatar

    For some reason I keep getting a compile error saying that HashSet is not generic.

  18. Wolfguarde Avatar

    Interesting little bug… somehow my first array parametre is last in the set's print output. Doesn't really affect anything in the tutorial, but I'm curious… why is this happening?

  19. Mistermaarten150 Avatar

    But which bob did it remove?

  20. khuong nguyen Avatar

    what should i do if i want to insert data from a text file to hash set?

Leave a Reply

Your email address will not be published. Required fields are marked *