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

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

4 Answers   Adobe,


How to call the m1() method of Base class in below snippet ? class Base { public void m1() { System.out.println("Base m1 "); } public void m2() { System.out.println("Base m1 "); } } ====================== class Derived extends Base { public void m1() { System.out.println("Derived m1"); } public void m3() { System.out.println("Derived m3"); } public static void main(String[] args) { Base ob=new Derived(); ob.m1(); //System.out.println("Hello World!"+ob.m1()); } }

6 Answers   Cap Gemini, TCS,


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

2 Answers   Inforica, Interface Software,


What is the use of hashcode in java ?

0 Answers  


what is mean by hasing and maping in java platform and advantage?

0 Answers   CTS,






HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS

0 Answers  


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

1 Answers  


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

0 Answers  


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

2 Answers   IBM,


What are the different types of classes implemented in the set interfaces? : java collections

0 Answers  


In hyderabad, which s/w training center is best for java, other than corejava what r the new tools to learn in java,which tool is best & have current requirement,pls give me information about java to learn ?

0 Answers  


How do you debug your java program?

2 Answers   HCL, Inforica,


Categories