suppose in a class there is a code like this:
{
Set hs=new Hashset();
hs.add(new Emp("kathy",1000));
hs.add(new Emp("kathy",2000));
}
how can u avoid the above code in your class as set won't
allow duplicate objects?

Answer Posted / harish

This can achieved by overriding equals and hashCode method

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many threads can I run java?

546


How many types of exception can occur in a java program?

538


Can we convert stringbuilder to string in java?

562


For class CFoo { }; what default methods will the compiler generate for you>?

622


What is merge sort in java?

585






why java uses class level type casting ?

2253


What is a ternary operator in java? What is an interface?

553


Where is java located?

501


Is null a keyword in java?

559


Explain the scope of a variable.

640


Is empty string in java?

544


What happens when I use / and % with a negative numerator?

538


What is math floor in java?

477


What is the static import?

592


Implementations of set interface?

569