Some common methods of strings:
int Length ()
String replace (charsequence oldstring,charsequence newstring)
Returns the string with the new string instead of the original string.
String substring (int beginindex)
String substring (int beginindex,int endIndex)
Returns a new string. This string contains all the code units from the Beginindex to the tail string or endIndex-1 in the original string.
String toLowerCase ()
String toUpperCase ()
StringBuilder class:
Sometimes a string, such as a key or a word from a file, needs to be built from a shorter string. The use of string connections to achieve this goal is less efficient. 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, first build an empty string builder, and then call the Append method each time you add
StringBuilder builder=new StringBuilder ();
Builder.append (CH); Append a single character
Buildr.append (str); Append a string
Call the ToString method when you need to build a string
String completedstring=builder.tostring ();
Some methods of the StringBuilder class:
int Length ()
StringBuilder Append (String str)
StringBuilder append (char c)
void Setcharat (int i,char c)//Set the I unit of code to C
StringBuilder Insert (int offset,char c)//Inserts a unit of code at offset position and returns this
StringBuilder Insert (int offset,string str)
StringBuilder Delete (int startindex,int endIndex)//delete the code unit from StartIndex to EndIndex-1 and return this
String toString ()
Java Learning 3_ some basic 3_16.5.7