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

"Sun Certified Java Programmer" This is one String , we need to print SCJP, write the java code dynamically? pls reply this questions

6 Answers   Photon,


my interviewer asked me what technical specification you used how to answer that question

0 Answers  


What are the classes in the java collection framework? : java collections

0 Answers  


what are callback methods?

3 Answers   iFlex,


how to deploy the web application ?

2 Answers   Accent,






Should we create system software ( e.g operating system ) in java ?

0 Answers  


How to use ANT?

2 Answers  


I have include a jsp page by using <jsp:include page="/.../xyz.jsp"/> The thing is that the xyz.jsp page has its submit button.When i click on that button the whole main page get refreshed.But i want to refresh only the xyz.jsp page.How could i achive it so that i can only refresh the xyz.jsp not the main page page?

4 Answers  


what is difference between vector and arraylist?.

4 Answers   C DAC, HCL,


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  


what is the difference between through and throws?

2 Answers   HCL,


what is filter ?

2 Answers   SolutionNET,






Categories