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
Why synchronization is important in java?
What are benefits of java?
What do you know about the garbage collector?
What is difference between iterator access and index access?
Why put method is used?
What is meant by distributed application? Why are we using that in our application?
What is the escape character in java?
What is the super void?
What is the main method java?
How do you write a scanner class in java?
How many bytes is string in java?
Is it compulsory for a try block to be followed by a catch block in java for exception handling?
What is a boolean in java?
Why Java doesn’t support multiple inheritance?
What advantage do java's layout managers provide over traditional windowing systems?