• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question About TreeSet?

 
Afzal Rehman
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why Output is 1? ,
 
Henry Wong
author
Marshal
Pie
Posts: 21422
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First, you example uses a HashSet -- not a TreeSet.... To answer your question, Sets don't allow duplicates.

Henry
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add method will return false if the object it is adding to the set is already there in the set.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashSet won't allow duplicates.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic