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

What is a two-pass assembler?

611


Is alive method in java?

508


What is the collections api in java programming?

557


What are the differences between processes and threads?

520


What is the difference between sleep and wait in java?

515






What are the six ways to use this keyword?

610


How do you create an array in java?

536


Which eclipse is best for java?

527


What does it mean to flush a file?

572


Can you call a method in a method?

533


Which is easier netbeans or eclipse?

614


Explain the difference between abstract classes and interfaces in java?

600


What do you understand by copy constructor in java?

492


Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.

524


What is string args [] in java?

540