1. The code point and the code unit Java string consist of a char sequence. Most commonly used Unicode characters can be represented using a single unit of code, while auxiliary characters need to be represented by a pair of code units. The length () method returns the number of code units required for the given string, expressed in UTF-16 encoding, to the actual length, i.e. the number of code pointsint cpcount = Str.codepointcount (0.str.length ())Calling Str.charat (n) returns the code unit of position n, where n is between 0-str.length ()-1 to get the code pointint index = str.offsetbycodepoints (0,i);int cp = STR.CODEPOINTAT (index);2. String APIchar charAt (int index)Returns the unit of code for the given location. You do not need to call this method unless you are interested in the underlying code unitint codepointat (int index) 5.0 Returns a code point starting or ending at a given positionint offsetbycodepoints (int startindex,int cpcount) 5.0 Returns the code point index, starting with the startindex code point, after the displacement Cpcountint CompareTo (String other)In dictionary order, returns a negative number if the string precedes other and returns a positive number if the string is behind other, or 0 if two strings are equalboolean endsWith (String suffix)Returns True if the string ends with suffixBoolean equals (Object other)Returns True if the string is equal to otherBoolean Equalsignorecase (String other)Returns True if the string is equal to other (ignoring case)int indexOf (String str)int indexOf (String str,int fromIndex)int indexOf (int cp)int indexOf (int cp,int fromIndex)Returns the start position of the first substring that matches the string str or the code point CP. This position is calculated starting at index 0 or Fromindex. If STR does not exist in the original string, return-1int lastIndexOf (String str)int lastIndexOf (String str,int fromIndex)int lastIndexOf (int cp)int lastIndexOf (int cp,int fromIndex)Returns the start position of the last substring that matches the string str or the code point CP. This position is calculated starting at the end of the original string or Fromindex.int Length ()Returns the length of a string int codepointcount (int startindex,int endIndex) 5.0 Returns the number of code points between startindex and endindex–1. Surrogate characters that are not paired are counted in the code pointString Replace (charsequence oldstring,charsequence newstring)Returns a new string that replaces all oldstring in the original string with NewString. You can use string and StringBuilder objects as charsequence parameters.Boolean startsWith (String prefix)Returns True if the string starts with a prefix stringString substring (int beginindex)String substring (int beginindex,int endIndex)Returns a new string. This string contains all the code units from Beginindex to tail or endIndex-1 in the original string.String toLowerCase ()Returns a new string. This string changes all uppercase letters in the original string to lowercase letters.String touppercase ()Returns a new string. This string changes all lowercase letters in the original string to uppercase letters.String trim ()Returns a new string. This string will delete the original string header and trailing spaces. Read the online API documentation and download the JDK API with a lot of String API 3. Building a string each time a connection string is built, a new string object is constructed, which is time consuming and wasteful. This problem can be avoided by using the StringBuilder class. If you need to build a string with many small pieces of string, you should follow thethe following steps。 1, First,build an empty string builder. StringBuilder builder = new StringBuilder ();2, when you need to add a part of the content,Call the Append () methodbuilder.append (CH); Append a single characterbuilder.append (str); Append a string3. When you need to build a string,Call the ToString method, you will get a string object that contains a sequence of characters in the builder.String completedstring = builder.tostring ();the predecessor of the StringBuilder is StringBuffer, which is slightly less efficient, but allows the operation of adding or removing characters in a multithreaded manner. If all strings are edited in a single thread, you should replace it with StringBuilder. stringbuilder%stringbuffer API The APIs for these two classes are the same. StringBuilder ()Constructs an empty string builderint Length ()Returns the number of code units in the builder or bufferStringBuilder Append (strigng str)Appends a string and returns thisStringBuilder Append (char c)Append a unit of code and return thisStringBuilder appendcodepoint (int cp)Append a code point and convert it to one or two units of code and return thisvoid Setcharat (int i,char c)Set the I code unit to CStringBuilder Insert (int offset,string str)Inserts a string at offset position and returns this StringBuilder Delete (int startindex,int endIndex)Delete the offset from startindex to endIndex-1 and return thisString toString ()Returns a string with the same content as the builder or buffer
Java basic Syntax < two > string strings