1.String string:
The string class is described in Java. Encapsulates the object with a string. The advantage is that you can easily manipulate the common data of strings. After the object is encapsulated, you can define n multiple properties and behaviors.
How do I define a string object? string s = "abc"; The data that is caused by double quotation marks is a string object.
features : Once the string is initialized, it cannot be changed and stored in a constant pool in the method area.
String S1 = "abc"; //S1 points to only one object in memory ABC .
string s2 = new String ("abc"); //S2 has two objects pointing to the content ABC ,new.
System.out.println (S1==S2);//false
System.out.println (s1.equals (S2));//true, in the string equals compares the contents of the strings.
Method of String:
1: Constructor method: converts a byte array or an array of characters into a string.
string S1 = new string ();//A string that creates an empty content.
String s2 = Null;//s2 does not have any object pointing, it is a null constant value.
string s3 = "";//s3 points to a specific string object, except that there is no content in the string.
New String (char[]);//Converts a character array into a string.
New String (char[],offset,count);//Converts a portion of a character array into a string.
2.StringBuffer String Buffer:
constructs a string buffer with no characters, with an initial capacity of three characters.
Characteristics:
1: You can modify the contents of a string.
2: is a container.
3: Is variable-length.
4: Any type of data can be stored in the buffer.
5: Eventually it needs to become a string.
3.StringBuilder String Buffer:
JDK1.5 appeared stringbuiler; constructs a string generator with no characters, with an initial capacity of three characters.
This class is designed to be used as StringBuffer a simple replacement for a string buffer that is used by a single thread (this is common). Method is the same as StringBuffer;
The difference between StringBuffer and StringBuilder:
StringBuffer thread safety.
StringBuilder thread is not secure.
single-threaded operation, using StringBuilder high efficiency.
Multi-threaded operation, using StringBuffer safe.
Java Basic Knowledge Summary (String, StringBuffer, StringBuilder)