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
What is an anonymous class in java?
what is object slice?
What is the similarity between dynamic binding and linking?
What is var keyword ?
What is gc()?
Can we declare main () method as non static?
Does java runtime require a license?
What is the difference between dom and sax parser in java?
Explain the difference between private, public, package and protected in java?
How to change value in arraylist java?
How do you square a number in java?
How many digits can a float hold?
What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?
Can we assign integer value to char in java?
How to print an arraylist in java?