For:
The Java platform provides two types of strings: string and Stringbuffer/stringbuilder, which can store and manipulate strings. Where string is a read-only string, meaning string content referenced by string cannot be changed. The string object represented by the Stringbuffer/stringbuilder class can be modified directly. StringBuilder is introduced in Java 5, and it is exactly the same as the StringBuffer method, except that it is used in a single-threaded environment because all aspects of it are not synchronized decorated. Therefore, it is also more efficient than stringbuffer.
Interview 1-Under what circumstances is a string connection with the + operator better than the Append method that calls the Stringbuffer/stringbuilder object?
Interview 2-Please say the output of the program below.
Class Stringequaltest {
public static void Main (string[] args) {
String S1 = "Programming";
String s2 = new String ("Programming");
String s3 = "program" + "Ming";
System.out.println (S1 = = s2);
System.out.println (S1 = = S3);
System.out.println (S1 = = S1.intern ());
}
}
Supplement: The Intern method of the string object will get a reference to the version of the strings object in the constant pool (if there is a string in the constant pool with the equals result of the string object is true), if there is no corresponding string in the constant pool, the string is added to the constant pool. It then returns a reference to the string in the constant pool.
What is the difference between string and StringBuilder, StringBuffer?