The operating object of the StringUtils method is the object of the Java.lang.string type, which is supplemented by the String type operation method provided by JDK, and it is safe (that is, if the input parameter is null, it will not throw out NullPoINTEEREXCETION, but instead do it. Instead, it does it. Corresponding processing, for example, if the input is NULL, it is also NULL, etc., you can view the source code specifically).
In addition to the constructor, there are more than 130 methods in StringUtils, and they are all static, so we can call StringUtils.xxx ()
Let me briefly introduce some commonly used methods below:
The StringUtils class is wrapped under ORG.APACHE.COMMONS.LANG.STRINGUTILS
String Isempty (String Str) and IsnoteMpty (String Str)
Copy code code as follows:
System.out.println (StringUtils.isempty (NULL)); // True
System.out.println (StringUtils.isempty (""); // True
System.out.println (StringUtils.isempty (""); // False Note: The isempty here does not do space processing
System.out.println (Stringutills.Isempty (" /T /N /F /R"); // False
System.out.println (StringUtils.isempty (" /B"); // false
System.out.println (StringUtils.isempty ("X-Rapido"); // False
System.out.println (StringUtils.isempty ("X"); // false
Copy code code as follows:
System.out.println (StringUtils.ISNOTEMPTY (NULL)); // False
System.out.println (StringUtils.ISNOTEMPTY (""); // False
System.out.println (StringUtils.ISNOTEMPTY (""); // True Note: The IsnoteMpty here did not do space processing
System.out.println (Stringutills.isnoteMpty (" /T /N /F /R"); // True
System.out.println (StringUtils.ISNOTEMPTY (" /B"); // True
System.out.println (StringUtils.ISNOTEMPTY ("X-Rapido"); // True
System.out.println (StringUtils.ISNOTEMPTY ("X"); // True
String Isblank (String Str) and IsnotBlank (String Str)
Including de -space replication code code as follows:
System.out.println (Stringutills.isblank (NULL)); // True
System.out.println (Stringutills.isblank (""); // True
System.out.println (Stringutills.isblank (""); // True
System.out.println (Stringutills.isblank (" /T /N /F /R"); // True
System.out.println (StringUtils.isblank (" /B"); // false
System.out.println (StringUtils.isblank ("X-Rapido"); // False
System.out.println (Stringutills.isblank ("X"); // false
Copy code code as follows:
System.out.println (StringUtils.isnotBlank (NULL)); // False
System.out.println (StringUtils.isnotblank (""); // false
System.out.println (StringUtils.isnotblank (""); // false
System.out.println (Stringutills.isnotblank (" /T /N /F /R"); // False
System.out.println (Stringutills.isnotblank (" /B"); // True
System.out.println (StringUtils.isnotblank ("X-Rapido"); // True
System.out.println (StringUtils.isnotblank ("X"); // True
String Trim (String Str) and TrimTonull (String Str) and TrimToEMPTY (String Str)
Copy code code as follows:
System.out.println (StringUtils.trim (NULL)); // null
System.out.println (Stringutills.trim (""); // "" ""
System.out.println (Stringutills.trim (""); // "" ""
System.out.println (StringUtils.trim (" /T /N /F /R"); // ""
System.out.println (StringUtils.trim (" /B"); // ""
System.out.println (StringUtils.trim ("X-Rapido"); // "x-rapido"
System.out.println (StringUtils.trim ("X"); // "x"
Copy code code as follows:
System.out.println (StringUtils.trimtonton (Null)); // null
System.out.println (Stringutills.trimtontonull (""); // null
System.out.println (Stringutills.trimtontonull (""); // null
System.out.println (Stringutills.trimtonull (" /T /N /F /R"); // null
System.out.println (StringUtils.trimtonull (" /B"); // null
System.out.println (StringUtils.trimtonull ("X-Rapido"); // "x-Rapido"
System.out.println (StringUtils.trimtonull ("X"); // "x"
Copy code code as follows:
System.out.println (Stringutills.trimtoempty (NULL)); // "" "" "
System.out.println (StringUtils.trimtoempty (""); // ""
System.out.println (StringUtils.trimtoempty (""); // ""
System.out.println (StringUtils.trimtoempty (" /T /N /F /R"); // ""
System.out.println (Stringutills.trimtoempty (" /B"); // "" "
System.out.println (Stringutills.trimtoempty (" /Bsss"); // SSS
System.out.println (StringUtils.trimtoempty ("X-Rapido"); // "x-Rapido"
System.out.println (StringUtils.trimtoempty ("X"); // "x"
String Strip (String Str) and Striptonull (String Str) and StripToEMPTY (String Str)
Copy code code as follows:
System.out.println (StringUtils.strip (NULL)); // null
System.out.println (StringUtils.strip (""); // "" "
System.out.println (StringUtils.strip (""); // "" "
System.out.println (StringUtils.strip (" /T /N /F /R"); // ""
System.out.println (StringUtils.strip (" /B"); // ""
System.out.println (StringUtils.strip (" /Bsss"); // SSS
System.out.println (StringUtils.Strip ("X-Rapido"); // "x-rapido"
System.out.println (StringUtils.strip ("X"); // "x"
Copy code code as follows:
System.out.println (StringUtills.Striptonull (Null)); // null
System.out.println (StringUtils.Striptonull (""); // null
System.out.println (StringUtils.Striptonull (""); // null
System.out.println (Stringutills.striptonull (" /T /N /F /R"); // Null
System.out.println (StringUtils.Striptonull (" /B"); // ""
System.out.println (Stringutills.Striptonull (" /Bsss"); // SSS
System.out.println (StringUtils.Striptonull ("X-Rapido"); // "x-Rapido"
System.out.println (StringUtils.Striptonull ("X"); // "x"
Copy code code as follows:
System.out.println (Stringutills.striptoempty (NULL)); // "" "" "
System.out.println (StringUtils.Striptoempty (""); // ""
System.out.println (StringUtils.Striptoempty (""); // ""
System.out.println (StringUtils.Striptoempty (" /T /N /F /R"); // ""
System.out.println (Stringutills.Striptoempty (" /B"); // "" "
System.out.println (Stringutills.Striptoempty (" /Bsss"); // SSS
System.out.println (StringUtils.StriptoEMPTY ("X-Rapido"); // "x-Rapido"
System.out.println (StringUtils.Striptoempty ("x"); // "x"
String Strip (String Str, String Stripchars)
Remove the characters in StripChars on both ends of Str. If the STR is null or equal to "", it returns itself. If StripChams is null or "", return Strip (String STR).
String StripStart (String Str, String Stripchars)
Similar to 11, remove the characters in StripChars front end in StripChars.
String Stripnd (String Str, String Stripchars)
Similar to 11, remove the characters in StripChars at the end of the Str.
String [] Stripall (String [] strs)
STRIP (String STR) in each string in the string array, and then return. If STRS is null or STRS length is 0, the Strs itself.
String [] Stripall (String [] strs, String Stripchars)
STRIP (String Stri, String Stripchars) in each string in the string array, and then return. If STRS is null or STRS length is 0, the Strs itself
Boolean Equals (String Str1, String Str2)
Compare whether the two string is equal, if both are empty, they are also considered equal.
Boolean equalSignorecase (String Str1, String Str2)
Comparing whether the two string is equal, it does not distinguish the case. If both are empty, they are also considered equal.
int indexof (String Str, Char Searchchar)
Return the character SearchChar first appeared in the string Str. If SearchChar does not appear in STR, it returns -1. If STR is null or "", it will also return to -1
int indexof (String Str, Char Searchchar, int Startpos)
Return the character SearchChar starts from StartPos for the first time in the string STR. If SearchChar does not appear in STR from Startpos, it returns -1. If STR is null or "", it will also return to -1
int indexof (String Str, String Searchstr)
Return the string SEARCHSTR for the first time in the string Str. If the STR is null or searchstr is NULL, it returns -1. If SearchStr is "", and the STR is not NULL, returns 0. If Searchstr is not in STR, return -1 will be returned -1
Int OrdinaLindexof (String Str, String Searchstr, int Ordinal)
Returns the position of Searchstr in the string Str, the position of the second place appears in the string Str. If Str = NULL or Searchstr = NULL or Ordinal <= 0, it returns -1
Copy code code as follows:
System.out.println (StringUtils.ordinalIndexof (null, "a", 1)); // -1
System.out.println (StringUtils.ordinalIndexof ("A", NULL, 1)); // -1
System.out.println (Stringutills.ordinalIndexof ("", "", ", 1)); // 0
System.out.println (Stringutills.ordinalIndexof ("AABAABAA", "A", 1); // 0
System.out.println (StringUtils.ordinalIndexof ("AABAABAA", "A", 2); // 1
System.out.println (StringUtils.ordinalIndexof ("AABAABAA", "B", 1); // 2
System.out.println (Stringutills.ordinalIndexof ("AABAABAA", "B", 2); // 5
System.out.println (StringUtils.ordinalIndexof ("AABAABAA", "AB", 1); // 1
System.out.println (Stringutils.ordinalIndexof ("AABAABAA", "AB", 2); // 4
System.out.println (StringUtils.ordinalIndexof ("AABAABAA", "BC", 1); // -1
System.out.println (Stringutils.ordinalIndexof ("AABAABAA", "", 1); // 0
System.out.println (Stringutills.ordinalIndexof ("AABAABAA", "", 2); // 0
INT INDEXOF (String Str, String Searchstr, Int Startpos)
Returning the string Searchstr starts from StartPos for the first time in the string Str.
Copy code code as follows:
System.out.println (Stringutills.indexof (null, "a", 1)); // -1
System.out.println (Stringutills.Indexof ("A", NULL, 1)); // -1
System.out.println (StringUtils.Indexof ("", "", 1); // 0
System.out.println (Stringutills.indexof ("AABAABAA", "A", 1)); // 1
System.out.println (Stringutills.indexof ("AABAABAA", "A", 2); // 3
System.out.println (Stringutills.indexof ("AABAABAA", "B", 1); // 2
System.out.println (Stringutills.Indexof ("AABAABAA", "B", 2)); // 2
System.out.println (Stringutills.indexof ("AABAABAA", "AB", 1); // 4
System.out.println (Stringutills.indexof ("AABAABAA", "AB", 2)); // 1
System.out.println (Stringutils.indexof ("AABAABAA", "BC", 1); // -1
System.out.println (Stringutills.indexof ("AABAABAA", "", 1); // 1
System.out.println (Stringutills.indexof ("AABAABAA", "", 2); // 2
INT LASTINDEXOF (String Str, Char Searchchar)
Basic principles are the same as Int indexof (String Str, Char Searchchar)
INT LASTINDEXOF (String Str, Char Searchchar, int Startpos)
Basic principles are the same as INT INDEXO (String Str, Char Searchchar, int Startpos)
int LastIndexof (String Str, String Searchstr)
Basic principles are the same as INT INDEXF (String Str, String Searchstr)
INT LASTINDEXOF (String Str, String Searchstr, Int Startpos)
Basic principles are the same as int indexof (String Str, String Searchstr, int StartPos)