Quiz: unfriend Method
Implement the unfriend(Person nonFriend) method. You want to update the value of the instance variable friends. Hint: Use the String method replace to remove the friend's name and the space that follows it.
|
friends = friends.replace(nonFriend.name + " ", ""); |
The trick is to replace the string that you previously added with an empty string. |
Corrected code should read:
friends = friends.replace(nonFriend.name + " ", "");