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 are multiple inheritances? Is it supported by java?

554


What is the method to expand and collapse nodes in a jtree?

701


What is charat java?

616


Can we override singleton class?

620


Can a final variable be initialized in constructor?

581






Explain about main thread in java?

723


What are different types of states exist for a thread?

652


What is final modifier?

643


What is meant by tab pans?

744


What is the base class in java from which all classes are derived?

609


Explain the difference between throw and throws in java?

636


How do you represent a space in regex java?

609


What is the default value of the local variables?

600


What does indexof mean?

616


What is Java Shutdown Hook?

721