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 are the types of interface used in the java collections? : java collections

0 Answers  


What is IOC in spring?

10 Answers   Centris,


please mail me the interview question based on java/j2ee

0 Answers   Wipro,


What are the main classes of the list interfaces? : java collections

0 Answers  


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

1 Answers   HCL,


Hi we have an urgent requirement for Java/J2ee technical lead position & also looking for "Java Guidewire claimcentre" experienced professional for Bangalore location if interested can reach srisanh@gmail.com

0 Answers  


what debugging tool that can be used to debug the java programs?

1 Answers   Inforica,


wnet use DAO design in u r project?

1 Answers   Godrej,


What are the uses of the set interfaces in the java collections? : java collections

0 Answers  


Write a postfix expression to (a*(b+c/d)*d-e)

4 Answers   Adobe,


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

2 Answers   IBM,


What is the enumerator of the java collection framework? : java collections

0 Answers  


Categories