Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Java HashSet Uses

  1. #1
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Java HashSet Uses

    I know this will probably be a ohhhhhhhh moment when someone explains this to me. What are some reasons or real world situations you might want to use a HashSet? From my understanding you need a Class that is considered .equal() to the class your looking for. So even though this is user defined if the class you have is pretty much equal to the class your trying to get in the HashSet then where is the need?

    side note I read that HashMaps can't have duplicates. Does this apply to the hash key or the Objects that are being held?

    Im new to most of the Collections so if there is anything wrong within my question showing that my understanding of either Hash Type is screwed up then please let me know.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Java HashSet Uses

    Time to go through some tutorials:
    The Set Interface (The Java™ Tutorials > Collections > Interfaces)
    Set Implementations (The Java™ Tutorials > Collections > Implementations)

    HashMaps can't have duplicates. Does this apply to the hash key or the Objects that are being held?
    You can find the answer to that in the API documentation for the Set interface.
    Set (Java Platform SE 6)

    db
    killutch likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Re: Java HashSet Uses

    Thanks for the reply I'll definitely check this out.

  4. #4
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Re: Java HashSet Uses

    Read both these links and it was exactly what I was looking for thanks for that. I'm sure ill be using HashSets in the future. Anyone else who might read this with a similar question its really worth reading at least the first link here.

    Quote Originally Posted by DarrylBurke View Post
    You can find the answer to that in the API documentation for the Set interface.
    Set (Java Platform SE 6)
    This question didn't really match with the title of the post but I didn't want to make a new thread for it. Your answer got me looking in the write direction but heres the link that answered that question Map (Java Platform SE 6) and if anyone wanted to know HashMaps can't have duplicate keys but they can have duplicate values(or secondary objects).

    example
    Java Code:
    HashMap<Integer, myClass> hashMap = new HashMap<Integer, myClass>();
    in such a case Integer can't have duplicates but myClass can.

Similar Threads

  1. HashSet
    By Dayanand in forum New To Java
    Replies: 7
    Last Post: 03-12-2011, 09:37 AM
  2. HashSet with array
    By pi4r0n in forum New To Java
    Replies: 4
    Last Post: 03-10-2011, 11:20 PM
  3. Getting value for key in HashSet
    By Venny in forum New To Java
    Replies: 12
    Last Post: 02-02-2011, 08:42 AM
  4. Adding to a HashSet
    By Neivaed in forum New To Java
    Replies: 6
    Last Post: 12-05-2010, 06:16 PM
  5. :( anyone here plz help on HashSet
    By waklo99 in forum New To Java
    Replies: 8
    Last Post: 09-20-2010, 03:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •