Wednesday 6 June 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...