string literal declaration: String string = "12345";
1, the concatenation of strings:
String str1 = "123";
String str2 = "456";
Method One:
System.out.println (str1 + SR2);
Method Two:
System.out. println (Str1.concat (str2));
2. Deletion and interception of strings:
String str = "123ASDZXVCAAAA"
Method One: Delete all the numbers in the string
System.out.println (Str.replaceall ("\\d", ""));
Method Two: intercept string, delete
1, System.out.println (str.substring (int i)); The string is truncated from subscript I, and the element preceded by I is taken away;
2, System.out.println (str.substring (int i, int j));//The string is truncated from subscript I to subscript j;
3, System.out.println (Str.replaceall ("A", "" ")); Replace all A in the STR string with "";
3, ASCII code conversion:
String str = "123ASDASD";
SYSTEM.OUT.PRINTLN (Str.charat (int i)); Gets the ASCII code for the character labeled I,
4. Get the specified subscript element
String str = "1234ABCD";
System. Out. println ("str.indexof (int i)"); Get the element labeled I;
5. Check if the string contains an element
String str = "123qwer";
if (Str.contanins ("123")) {
System.out.println ("contains 123")
}
Java Basics String