In HashSet duplicates are allowed while adding to the HashSet,
but while retreiving the object from HashSet is not shown the
duplicate values, WHY ?




Answers were Sorted based on User's Feedback



In HashSet duplicates are allowed while adding to the HashSet, but while retreiving the object fro..

Answer / brijendra kumar (xavient)

Actually in HashSet we are able to add the duplicate value,
but at the execution time JVM ignore the duplicate value.
HashSet<String> T= new HashSet<String>();
T.add("k");
T.add("k");
System.out.println("size" +T.size());
when we execute these line of code then we got the size of
HashSet is 1.
Due to this reason we are unable to iterate the duplicate
value from HashSet.

Is This Answer Correct ?    7 Yes 2 No

In HashSet duplicates are allowed while adding to the HashSet, but while retreiving the object fro..

Answer / shashi

Because HashSet class will override equals and hashcode method internally.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer




More Java J2EE AllOther Interview Questions

which book is the best for preparing for SCWCD 1.5

4 Answers   Google,


lll

1 Answers  


i need java 1+ experience resume on java developer kindly send me my mail id:srikanthreddy1.marla@gmail.com

1 Answers  


whatis arguments &what is default argument

2 Answers   CTS,


can u draw class/object diagram for ATM

0 Answers   HCL, Zycus Infotech,






How to implement or use the singleton class in java?

3 Answers  


What is the Spring2.5 MVC Navigation flow?

1 Answers   IBM,


what is acl(access control list)?

1 Answers   HCL, Athena,


when exactly should we use throws ,and wen exactly should we use the try and catch for exceptional handling

0 Answers  


What is an Ioc pattern? There are assemblies in .net for establishing this task, Whats the special in Java /j2ee technologies about IOC

2 Answers  


Can any one tell me How to explain bank project desription in interview

3 Answers   Infosys, Wipro,


what is the difference between checked and unchecked Exceptions?

4 Answers   CTS,






Categories