W
www
Hi,
I cannot figure out how to delete an entry from a Map(HashMap). For
example, suppose I have a class Person and 3 objects of that
type(personA, personB and personC):
public class Person {
private String name;
....//
public String getName{
return name;
}
}
personA is with name of "John", personB and personC are with other names.
Map<Person> map = new HashMap<Person>();
//so easy to add to Map
map.add(personA);
map.add(personB);
map.add(personC);
....
//now, I want the map only has the guy with name of "John", i.e. I want
to delete personB and personC from map. I felt that it is so difficult.
Thank you for your help.
I cannot figure out how to delete an entry from a Map(HashMap). For
example, suppose I have a class Person and 3 objects of that
type(personA, personB and personC):
public class Person {
private String name;
....//
public String getName{
return name;
}
}
personA is with name of "John", personB and personC are with other names.
Map<Person> map = new HashMap<Person>();
//so easy to add to Map
map.add(personA);
map.add(personB);
map.add(personC);
....
//now, I want the map only has the guy with name of "John", i.e. I want
to delete personB and personC from map. I felt that it is so difficult.
Thank you for your help.