String class knowledge consolidation

First to a face questions now
face questions a
String A = "ab";
String b = "A" + "b";
SYSOUT (A == b)
The answer is it true or false?
Let's analyze the process together
when you create a variable, constant pool will be opened in a storage space ab, then assign an address to a space;
when b variables are created, the compiler will automatically + out of the result of the operation, the equivalent of b == "ab", this time JVM will first determine whether there is a constant pool, direct reference to the address of the object assigned to the variable b, and therefore the same piece of address with a b are pointing to the constant pool, so the answer is true .
Two face questions
String a = "ab &";
; b = new new String String ( "ab &")
SYSOUT (a == b)
creates a problem as a variable to keep
the time b to create a string using new String (str) mode, If the presence of the constant pool, the stack into the copy, and point b heap address; if the constant pool does not exist, a new one into the constant pool, and copy into the pile, and point b pile address. So a string value with the constant pool b pointed to is not the same one, the answer is false.

Guess you like

Origin blog.51cto.com/14380904/2406261