我需要编写一个方法来搜索特定成员的俱乐部会员的对象数组,并且如果找到该成员则返回true。这是我现在拥有的。如何在对象数组中搜索特定的字符串?
public boolean isMember (String name){
boolean found = false;
int arrayIndex = 0;
while(arrayIndex < members.length && !found){
if(members[arrayIndex] == name){
found = true;
}
arrayIndex++;
}
return found;
}
不要使用''==来比较字符串值。使用'equals()'。 –