public static void main(String[] args){
/* lots of codes */
    if(profile.addFriend(buffernametwo)){
      boolean a = profile.addFriend(buffernametwo);
      System.out.println(a); 
     //prints false; however if I directly put profile.addFriend(buffernametwo) 
     //and follow the debugger, it will appear true
      /* lots of codes */
    }
/* lots of codes */
//the following method is in a different class
public boolean addFriend(String friend) {
        for(int i = 0;i < profile_friend.size();i++){
        //Here is the point
            if(friend == profile_friend.get(i)){
                return false;
            }
        }
        profile_friend.add(friend);
        return true;
/* lots of codes */
private ArrayList profile_friend = new ArrayList();
}
  The question is in the comment of the code
 
No comments:
Post a Comment