Java collection# set quiz
Hi
Today I am going to demonstrate you the property of set with the small code snippet.
Set set=new hashset();
set.add("suresh");
set.add(1);
This is illegal.
You may ask why why it is illegal.
The answer is we have added items belonging to completely different data types.
so when internally set calls sort operation it cannot perform sort operation on completely different data types.
That's why we can not add items of different data type in the set.
For Java training please drop mail to:
Sureshfc@yahoo.com
Labels: interview question, java, set, tough collectio. interview question
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home