I'm trying to add an object to a set if the map value matches an argument. the map is set up as:-
Map<String, Person> people = new HashMap<>();
so far I have tried:-
public Set<Person> findPersonInAgeCat(char ageCat) {
Set<Person> anAge = new HashSet<>();
for (Person eachPerson : people.values()) {
boolean result = personSet.containsValue(ageCat);
if (result) {
anAge.add(eachPerson);
}
return anAge;
ok so, now i have tried this.
public Set<Person> findPeopleInAgeCat(char ageCat)
{
Set<Person> anAge = new HashSet<>();
for (Person peopleValues : people.values())
{
Set<Person> values = new HashSet<>();
values.add(peopleValues);
for (Person info : values)
{
if (values.contains(ageCat))
{
anAge.add(info);
}
}
}
return anAge;
}
Which compiles but doesn't add any items to the set. I have created the instances of People and they are added to the Map with names, address, and age category, but still not adding any people to the set.