• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding elements into HashSet  RSS feed

 
dhrubo bhattacharjee
Greenhorn
Posts: 23
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about how add method in the HashSet works. I am relatively new to Java so please don't mind if this too naive. I was looking into the source code for HashSet and found that the 'add' method in the HashSet is saving the values in a HashMap.



What I figured out is that the 'e' is the key and the add method adds the new element as a key and not as a value and thus the HashSet will have no duplicates. What I want to know is if PRESENT is used as a dummy value which the Set does not care about ? Please let me know.
Thanks
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Does it answer your question?
 
dhrubo bhattacharjee
Greenhorn
Posts: 23
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So dosen't it takes more memory to store those references to the PRESENT object?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More memory than what alternative?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!