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
Is upper case in java?
Write a program to calculate factorial in java?
How do you join strings in java?
Is alive and join method in java?
Why is string buffer better than string ?
What is final access modifier in java?
What is a java list?
What are the advantages of java over C++?
Explain the polymorphism principle?
What is meant by polymorphism?
What is the main use of generics in java?
Why we override equals() method?
Can we override static methods in java?
Is the empty set a singleton?
Difference between static and dynamic class loading.