Java --------------- String basic interview questions
Package stu. love. a;/* String: */public class StringDemo {public static void main (String [] args) {// the String is a constant. Once a String is created, the String ss = "hello"; ss = "world"; System. out. println (ss); // special case:/* when defining s2, go to the constant pool to check whether the string "1000phone" exists. If the constant pool already exists, do not create it, otherwise, when defining s3, check whether the constant pool has the String "1000phone". If the result exists, */String s2 = "1000 phone" is no longer created "; string s3 = "1000 phone"; System. out. println (s2 = s3); // trueString s4 = new String ("1000 phone"); System. out. println (s2 = s4); // false // String overwrites the boolean equals (Object obj) method in the Object to determine whether the content of the two strings is the same as that of System. out. println (s2.equals (s4); // interview question: several objects are created in the following two sentences: String s5 = "1000 phone "; // The object is the String "1000 phone" String s6 = new String ("1000 phone"); // If the constant pool contains "1000 phone", there is only one object, this object is new String () // If the constant pool does not contain "1000 phone", there are two objects, the two are new String () and "1000 phone "}}