Java string problem

the question may be dementia, but I haven"t found it for a long time. Look for the answer-_ | |

String A = "aaa";
String B = A + "bbb";

A = "AAA";

System.print(B);

I want the output to be "AAAbbb" instead of "aaabbb"

ask for advice


B where a new object has been created has nothing to do with A


String A = "aaa". Such a string is stored in the constant pool of characters in the method area. The situation described by the subject occurs in the reference type. You can try String A = new String ("aaa");
B = A;
A = new String ("AAA");
putting a string into heap memory in this way may lead to a description of the subject.


 

the earliest answer has already mentioned that there is no correlation between your An and B after the change.
String A = "aaa";
String B = A + "bbb";

A = "AAA";
B = A + "bbb"; / / at least this

System.out.print (B);

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3892e-406b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3892e-406b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?