Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / venkata rao ummadisetty

Hi,

Can any one provide a full Example for using HashCode and
equals method

class Emp{
private String name;
private int salary;
Emp(String s,int p){
this.name=s;
this.salary=p;
}

public String toString(){
return name+":"+salary;

}

}

// In public static void main method

Set hs=new HashSet();
hs.add(new Emp("kathy",1000));
hs.add(new Emp("kathy",2000));
hs.add(new Emp("kathy",2000));
java.util.Iterator er=hs.iterator();

while(er.hasNext()){
System.out.println(er.next());}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we create an object of private class?

952


What is qualitative variable?

910


Differentiate between vector and array list.

1047


I want to persist data of objects for later use. What’s the best approach to do so?

911


What is difference between static class and singleton pattern?

1008


Is set ordered?

960


What is meant by tab pans?

1214


if u open login & logout ,how can udisplay the timelogin & logout members ?

2268


What is a numeric digit?

1071


How do you test a method for an exception using junit?

1189


What is Mutex (Mutual Exclusion Object) ?

1128


How many types of constructors are used in java?

1154


What java is used for?

1056


what is meant by Garbage collection?

1073


How to instantiate member inner class?

1063