Java record-25-String in-depth analysis
In-depth analysis of the String class in Java 1. Definition of the String class in Java source code: public final class String extends Object implements Serializable, Comparable <String>, CharSequence2.String class represents the String. All character strings (such as "abc") in Java programs are implemented as such instances. 3. strings are constants. Their values cannot be changed after creation. The string buffer supports variable strings. Because the String object is unchangeable, it can be shared. For example: String str = "abc"; equivalent to: char data [] = {'A', 'B', 'C'}; String str = new String (data ); 4. the String class can be used to check a single character, compare String, search String, extract substring, create a copy of String, and convert all characters to uppercase or lowercase letters. The case-sensitive ing is based on the Unicode Standard Edition specified by the Character class. 5. the Java language provides special support for String concatenation symbols ("+") and conversion of other objects into strings. String concatenation is implemented through the StringBuilder (or StringBuffer) class and its append method. String Conversion is implemented using the toString method. This method is defined by the Object class and can be inherited by all classes in Java. 6. string ss1 = "hello"; String ss2 = "world"; String ss3 = ss1 + ss2; System. out. println (ss3); since the string is a constant, it cannot be changed once created. Ss3, ss1, and ss2 are three different objects. ss3 is a new object, not merged by ss1 and ss2. Therefore, when you use + to splice strings, a new object is generated instead of adding content to the original String object.