Deep anatomy of the String class in Java
Definition of String class in 1.Java source code:
Public final class String extends Object implements Serializable, Comparable<string>, charsequence
2.Stringclass represents a string. All string literals (such as) in a Java program "abc" are implemented as instances of this class.
3. Strings are constants, and their values cannot be changed after they are created. A string buffer supports variable strings. Because the String object is immutable, it can be shared. For example: String str = "ABC";
Equivalent to: char data[] = {' A ', ' B ', ' C '}; String str = new string (data);
4. String The class includes methods that can be used to examine a single character of a sequence, compare strings, search strings, extract substrings, create a copy of a string, and convert all characters to uppercase or lowercase. Case mappings are based on Character the Unicode standard version specified by the class.
The 5.Java language provides special support for string concatenation symbols ("+") and for converting other objects to strings. string concatenation is StringBuilder implemented through the (or StringBuffer ) class and its append methods. String conversions are implemented by methods that are toString 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 strings are constants, they cannot be changed once they are created. SS3 and SS1, SS2 are three different objects, SS3 is a newly generated object, not SS1 and SS2 stitching. So when using the + stitching string, a new object is generated instead of adding content to the original string object.
Java record -25-string class depth profiling