A Java string is a Unicode Character Sequence. Java does not have a built-in String type. Instead, a predefined String class is provided in the standard Java class library, which is located in the java. lang package. The Compiler imports this package by default. Strings are processed as String objects.
Method for creating a String object:
1. String s = "Hello World ";
2. String s = new String ();
3. String s = new String ("Hello World ");
Obtain the length of a string: string name. length ();
String comparison: String 1. equals (string 2); // the same letter, the same case is different
String 1. Using signorecase (string 2); // case insensitive during comparison
The English character in the toLowerCase () Conversion string is lowercase.
The English characters in the toUpperCase () Conversion string are uppercase letters.
String connection:
1. Use the "+" operator,
2. Use the concat () method of the String class
Common string extraction and query methods:
Method description
Public int indexOf (int ch) searches for the first occurrence character ch
Public int indexOf (String value) Search for the first occurrence String value
Public int lastIndexOf (int ch) searches for the last occurrence character ch
Public int lastIndexOf (String Value) Search for the last String value
Public String substring (int index) extract the String part starting from the Position index
Public String substring (int beginIndex, int endIndex); extract the String section between beginIndex and endIndex
Public String trim () removes leading and trailing spaces of the String and returns a copy.