我有2个班级的Gym和GymMember。目前Gym会将所有gymMember存储在HashMap GymMembers中,其中String是其成员ID(String)。
gymMember包含变量:
this.fullName = aName;
this.address = anAddress;
this.area = anArea;
我要去的是在HashMap GymMembers中进行搜索,以找出区域1中哪些成员存储在变量this.area中,然后将GymMember对象返回到一个新集合。
到目前为止,我已经做到了:
public void findCustomersInArea(int x)
{
// create a list to store all Customers
List<gymMember> aMember = new ArrayList<gymMember>();
// iterate all entries in the map
for (Map.Entry<String, gymMember> a: gymMembers.entrySet())
{
// get the customer
gymMember newMember = a.getArea();
if (newMember.getArea() == x) {
// do what you need to add to a list
newMember.add(newCustomer);
}
}
}
有谁知道我要去哪里错了?
最佳答案
gymMember newMember = a.getValue ();
if (newMember.getArea() == x) {
// do what you need to add to a list
aMember.add(newMember);
}