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 the use of log4j and how to make use of that in a application?

2 Answers  


what is the difference between banking and insurance domain?

2 Answers  


what is hibernate ceteria ?

4 Answers   Fidelity,


What are the different types of collections views being provided by the map interface? : java collections

0 Answers  


When to use the Collection Classes(HashSet, LinkedHashSet, TreeSet....etc) in real time scenario ?

1 Answers   Cap Gemini,


whats the relation ship between LDAP and JNDI?

1 Answers  


lll

1 Answers  


what is class/object diagram

3 Answers   Zycus Infotech,


What are the different types of features of the java collections framework? : java collections

0 Answers  


what is java virtual machine

4 Answers  


How do you create UserTransaction Object? How do you rollback a transaction in a method?

1 Answers   HCL,


what is the IDE that you have used to write your java programs?

2 Answers   Inforica, Interface Software,


Categories