The character string must be "" to include text. Each character in the string is constructed using Unicode characters.
String class:
| Method |
Description |
| Length () |
Returns the string length. |
| Equals () |
Determines whether the character in the source string is equal to the character in the specified string. |
| Tolowercase () |
Lowercase English characters in the conversion string |
| Touppercase () |
The English characters in the conversion string are uppercase letters. |
| |
|
| Byte. parsebyte (string) |
Break down characters into bits |
| Integer. parseint (string) |
|
| Long. parselong (string) |
|
|
... |
|
String is not the basic data type of Java. String is the class provided under the java. lang package.
To obtain the characters in a string:
| Method |
Description |
| Char charat (INT index) |
Returns the characters at the specified index. |
| Int indexof (INT ch) |
Returns the index location found at the first time of the specified character. |
| Int indexof (string Str) |
Returns the first index location of the specified string. |
| Int lastindexof (INT ch) |
|
|
String substring (INT beginindex [, INE endindex]) |
|
|
Char [] tochararray () |
Converts a string to a character array. |
| Endswith () |
Determines whether the string ends with the specified text. |
When constructing a String object, in addition to specifying the String constant directly after =, you can also use a character array to construct the object:
Char [] Name = {'C', 'A ',...};
String STR = new string (name );
In Java, once a String object is configured, its content remains unchanged.
Use = to assign a String object to a reference name, which means to change the object referenced by the name, if the referenced String object has no other names for reference, it will be reclaimed by Java's "Garbage Collection" mechanism as appropriate.
A string pool is maintained during Java execution. For some string objects that can be shared, you can check whether the same string content exists in the string pool. If yes, you can directly return the string object instead of directly creating a new String object, to reduce memory consumption.
Concatenating strings with + produces a New String object. The intern () method checks whether a String object with the same string part exists in the string pool.
Stringbuilder class
The Java. Lang. stringbuilder class has been provided since j2se 5.0. By default, the object generated by this class has a length of 16 characters. If you need to frequently append strings, using stringbuilder will make the program more efficient.
Capacity () can return the size of characters that an object can currently hold.
The insert () method can be used to insert specified characters.
The deletechar () method can delete characters at a specified position.
The reserve () method can reverse a string.