1. What is the mechanism of string creation and storage?
String s = "abc";//Put "abc" in the constant area, which is generated at compile time String s = "ab" + "c";//Convert "ab" + "c" to the string constant "abc" and put it in the constant area String s = new String ("abc");//Put "abc" on the heap at runtime, and create it if "abc" does not exist in the constant pool. Do not create if it already existsInterview questions:
How many objects does new String("abc") create?
Answer: one or two. If there is "abc" in the constant pool, only one object will be created; if there is no string "abc" in the constant pool, then two objects will be created