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

What is need of DAO? Write one simple DAO example?

2 Answers   IBM,


what is java virtual machine

4 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  


Hi frnds how to lock an user when he enter wrong credentials more than 3 time using java or j2ee tech take username and password in a bean no need to connect DB and validate give me some sample application code or links its urgent for me thanks in advance

0 Answers   NSN,


Is it Mandatory to map each pojo class variable with table column in Hibernate? Is there any alternative to skip some of those? Thanks in advance...

2 Answers   Span Systems,






Is it possible to create Userdefined Unchecked Exception also?If Yes, give an example?

1 Answers   HCL,


What are maps interfaces in the java collections? : java collections

0 Answers  


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

0 Answers  


What is the Spring2.5 MVC Navigation flow?

1 Answers   IBM,


What is markup language?

1 Answers  


What are the considerations to be made in case of loops in java ?

0 Answers  


What are the types of interface used in the java collections? : java collections

0 Answers  


Categories