Wednesday, June 6, 2018

boolean - A strange String assignment phnomenon in Java

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

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...