The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question About TreeSet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question About TreeSet?" Watch "Question About TreeSet?" New topic
Author

Question About TreeSet?

Afzal Rehman
Ranch Hand

Joined: Dec 16, 2009
Posts: 39


Why Output is 1? ,


SCJP 6.0
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19926
    
  43


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

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234
Add method will return false if the object it is adding to the set is already there in the set.
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
HashSet won't allow duplicates.
 
Consider Paul's rocket mass heater.
 
subject: Question About TreeSet?
 
It's not a secret anymore!