1, conceptually, the Java string is a sequence of dead Unicode characters, Java does not have a built-in string type, but in the standard Java class Library provides a predefined class, called String. strings are enclosed in "".
2, sub-string:
(Intercept string function) Substring method: String greeting = "Hello";
String s = greeting.substring (0,3); Output Result: Hel
The first parameter represents the first position that you do not want to copy (and does not include this number), the length of the string is: 3-0=3
Stitching strings with +
3. Immutable string:
A string class object is called an immutable string in a Java document: If you need to modify it, use the interception and stitching method
4. Check if strings are equal
Equals method: S.equals (t) equals returns True, otherwise false string constants and string variables can be compared
Equalsignorecase method (case insensitive)
Must not use = = To verify that two strings are equal
5, empty strings and Null strings:
Empty string: "" Length of 0 strings, empty string is a Java object
A string variable can also hold a special value named NULL, which means that no object is currently associated with the variable.
6. Code points and code units:
The Java string consists of a char sequence, and the char data type is a unit of code that uses UTF-16 encoding to represent Unicode code points.
The length method returns the number of code units required to represent the given string in UTF-16 encoding.
Example: String greeting = "Hello";
int n = greeting.length (); is 5
Calling S.charat (n) returns the unit of code for position n, where n is between 0~s.length ()-1
Java counts the code units and code points in a string starting from 0
7. String API:
The string class in Java contains more than 50 methods.
8. Build a string:
StringBuilder () constructs an empty string builder
int length () returns the number of code units in the builder or buffer
StringBuilder append (String str) appends a string and returns this
StringBuilder append (char c) appends a unit of code and returns this
StringBuilder appendcodepoint (int cp) appends a code point and converts it to one or two units of code and returns this
void Setcharat (int i,char c) Set the I unit of code to C
StringBuilder Insert (int offset,string str) inserts a string at offset position and returns this
StringBuilder Insert (int offset,char c) Inserts a unit of code at offset position and returns this
StringBuilder Delete (int startindex,int endIndex) deletes the code unit from StartIndex to EndIndex and returns this
String to String () returns a string that is the same as the builder or buffered content
Java Basics-String