Various methods of Java String class
Method related to string inspection
| Method |
operation |
Argument type |
Return type |
| equals |
Check if the contents are equal |
String |
boolean |
| equalsIgnoreCase |
Check if the content is equal, ignoring case |
String |
boolean |
| length |
Check the length of the string |
String |
int |
| isEmpty |
Check if it is an empty string |
String |
int |
Methods for string search
| Method |
operation |
Argument type |
Return type |
| contains |
Find out if it contains a string |
String |
boolean |
| startsWith |
Find out if it starts with the specified string |
String |
boolean |
| endsWith |
Checks if it ends with the specified string |
String |
boolean |
| indexOf |
Find out where the specified character or string first appears |
String |
int |
| lastIndexOf |
Search from the back for the specified character or string to find out where it first appears |
String |
int |
Method related to string clipping
| Method |
operation |
Argument type |
Return type |
| charAt |
Cut out one character at the specified position |
int |
String |
| startsWith |
Checks if it starts with the specified string |
String |
boolean |
| endsWith |
Checks if it ends with the specified string |
String |
boolean |
| indexOf |
Find out where the specified character or string first appears |
String |
int |
| lastIndexOf |
Search from the back for the specified character or string to find out where it first appears |
String |
int |
Methods for string conversion
| Method |
operation |
Argument type |
Return type |
| toLowerCase |
Convert uppercase to lowercase |
String |
String |
| toUpperCase |
Convert uppercase to lowercase |
String |
|
| trim |
Remove leading and trailing whitespace |
String |
|
| replace |
Replace with the specified string |
String,String |
String |
| reverse |
Invert the specified string |
String |
|
References
Java introductory practice that you can understand clearly