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

Why synchronization is important in java?

666


What are benefits of java?

675


What do you know about the garbage collector?

695


What is difference between iterator access and index access?

744


Why put method is used?

645






What is meant by distributed application? Why are we using that in our application?

650


What is the escape character in java?

611


What is the super void?

564


What is the main method java?

625


How do you write a scanner class in java?

642


How many bytes is string in java?

731


Is it compulsory for a try block to be followed by a catch block in java for exception handling?

686


What is a boolean in java?

671


Why Java doesn’t support multiple inheritance?

723


What advantage do java's layout managers provide over traditional windowing systems?

633