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 / mushtaq hussain

by implementing equals and toHashCode method in emp Class

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you sort objects in java?

522


What is the super void?

463


What is array and arraylist in java?

535


What are the advantages and disadvantages of object cloning?

581


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

589






What is widening and narrowing in java? Discuss with an example.

563


when you will synchronize a piece of your code? : Java thread

533


What is string [] java?

530


What is the difference between a checked and an unchecked exception?

556


What is singleton service?

516


What technique is carried out to find out if a particular string is empty?

578


What is difference in between java class and bean?

574


What is the difference between preemptive scheduling and time slicing in java programming?

542


What do you understand by access specifiers in Java?

590


What string is utf8?

553