-1

I need write a method that searches an object array of Club Members for a specific member and returns true if the member is found. This is what I have now.

 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;
}   
user3038888
  • 25
  • 1
  • 3
  • 6

2 Answers2

1

In java, strings can only be compared with the .equals method, not with ==.

You can change your if condition like this:

 if(members[arrayIndex].equals(name))
Deena
  • 343
  • 1
  • 11
1

Try this

 found = Arrays.asList(members).contains(name)
tgpatel
  • 134
  • 5