Common string APIs in Java
These APIs are encapsulated in a
Import Java.lang; (default import does not need to be imported manually)
String. Length ()
Returns the length of a string
String 1.equals (String 2)
Determine whether the contents of two strings are consistent ( cannot be used = =)
String 1.equalsIgnoreCase (String 2)
Determine whether the contents of two strings are consistent (case insensitive)
String. toLowerCase ()
Returns a lowercase string
String. toUpperCase ()
Return uppercase String
String 1.concat (String 2)
Return string 1 to String 2 (equivalent to "string 1" + "String 2")
String 1. CompareTo (String 2)
Returns the value of string 1 compared to string 2 (each of which is the same as ASCII) returns 0
/** Common Extraction method (if not found return-1) */public int indexOf (char ch)/** Returns the first occurrence of the character Ch's position */public int indexOf (string value)/** returns the first occurrence of the string The position of value */public int indexOf (char ch)/** returns the position of the last occurrence of CH, */public int indexOf (string value)/** returns the position of the last occurrence of the string value */ public string substring (int index)/** extracts the string portion starting from the position index */public string substring (int beginindex,int endindex)/** extract from the starting position of the cable String part */public string trim ()/** Returns a copy of the call string without any spaces before the end position index (excluding the end position) */
/** Common Splitting method */
The/** string class provides the split () method to split a string into a substring result as an array of strings returned */
public class Demo {public static void Main (string[] args) { String std = "A,b,c"; string[] Strarray = Str.split (","); /** Sometimes the split delimiter will conflict with the keyword of the regular expression, then escape a bit, such as Str.split ("\\|"); Use | as delimiter * /for (String item:strarray) System.out.println (item);//output a B c }}
Common string APIs in Java