类 StringUtils


  • public abstract class StringUtils
    extends java.lang.Object
    The utilities class for String
    从以下版本开始:
    1.0.0
    作者:
    Mercy
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static java.lang.String EMPTY  
      static java.lang.String[] EMPTY_STRING_ARRAY  
      static int INDEX_NOT_FOUND
      Represents a failed index search.
    • 构造器概要

      构造器 
      构造器 说明
      StringUtils()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static boolean contains​(java.lang.String value, java.lang.CharSequence part)  
      static boolean endsWith​(java.lang.String value, java.lang.String part)  
      static boolean isBlank​(java.lang.String value)  
      static boolean isEmpty​(java.lang.String value)  
      static boolean isNotBlank​(java.lang.String value)  
      static boolean isNotEmpty​(java.lang.String value)  
      static int length​(java.lang.String value)  
      static java.lang.String replace​(java.lang.String text, java.lang.String searchString, java.lang.String replacement)
      Replaces all occurrences of a String within another String.
      static java.lang.String replace​(java.lang.String text, java.lang.String searchString, java.lang.String replacement, int max)
      Replaces a String with another String inside a larger String, for the first max values of the search String.
      static java.lang.String[] split​(java.lang.String value, char delimiter)  
      static java.lang.String[] split​(java.lang.String value, java.lang.String delimiter)  
      static boolean startsWith​(java.lang.String value, java.lang.String part)  
      static java.lang.String substringAfter​(java.lang.String str, java.lang.String separator)
      Gets the substring after the first occurrence of a separator.
      static java.lang.String substringAfterLast​(java.lang.String str, java.lang.String separator)
      Gets the substring after the last occurrence of a separator.
      static java.lang.String substringBefore​(java.lang.String str, java.lang.String separator)
      Gets the substring before the first occurrence of a separator.
      static java.lang.String substringBeforeLast​(java.lang.String str, java.lang.String separator)
      Gets the substring before the last occurrence of a separator.
      static java.lang.String substringBetween​(java.lang.String str, java.lang.String tag)
      Gets the String that is nested in between two instances of the same String.
      static java.lang.String substringBetween​(java.lang.String str, java.lang.String open, java.lang.String close)
      Gets the String that is nested in between two Strings.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • EMPTY

        public static final java.lang.String EMPTY
        另请参阅:
        常量字段值
      • EMPTY_STRING_ARRAY

        public static final java.lang.String[] EMPTY_STRING_ARRAY
      • INDEX_NOT_FOUND

        public static final int INDEX_NOT_FOUND
        Represents a failed index search.
        另请参阅:
        常量字段值
    • 构造器详细资料

      • StringUtils

        public StringUtils()
    • 方法详细资料

      • length

        public static int length​(java.lang.String value)
      • isEmpty

        public static boolean isEmpty​(java.lang.String value)
      • isNotEmpty

        public static boolean isNotEmpty​(java.lang.String value)
      • isBlank

        public static boolean isBlank​(java.lang.String value)
      • isNotBlank

        public static boolean isNotBlank​(java.lang.String value)
      • split

        public static java.lang.String[] split​(java.lang.String value,
                                               char delimiter)
      • split

        public static java.lang.String[] split​(java.lang.String value,
                                               java.lang.String delimiter)
      • contains

        public static boolean contains​(java.lang.String value,
                                       java.lang.CharSequence part)
      • startsWith

        public static boolean startsWith​(java.lang.String value,
                                         java.lang.String part)
      • endsWith

        public static boolean endsWith​(java.lang.String value,
                                       java.lang.String part)
      • replace

        public static java.lang.String replace​(java.lang.String text,
                                               java.lang.String searchString,
                                               java.lang.String replacement)

        Replaces all occurrences of a String within another String.

        A null reference passed to this method is a no-op.

         StringUtils.replace(null, *, *)        = null
         StringUtils.replace("", *, *)          = ""
         StringUtils.replace("any", null, *)    = "any"
         StringUtils.replace("any", *, null)    = "any"
         StringUtils.replace("any", "", *)      = "any"
         StringUtils.replace("aba", "a", null)  = "aba"
         StringUtils.replace("aba", "a", "")    = "b"
         StringUtils.replace("aba", "a", "z")   = "zbz"
         
        参数:
        text - text to search and replace in, may be null
        searchString - the String to search for, may be null
        replacement - the String to replace it with, may be null
        返回:
        the text with any replacements processed, null if null String input
        另请参阅:
        replace(String text, String searchString, String replacement, int max)
      • replace

        public static java.lang.String replace​(java.lang.String text,
                                               java.lang.String searchString,
                                               java.lang.String replacement,
                                               int max)

        Replaces a String with another String inside a larger String, for the first max values of the search String.

        A null reference passed to this method is a no-op.

         StringUtils.replace(null, *, *, *)         = null
         StringUtils.replace("", *, *, *)           = ""
         StringUtils.replace("any", null, *, *)     = "any"
         StringUtils.replace("any", *, null, *)     = "any"
         StringUtils.replace("any", "", *, *)       = "any"
         StringUtils.replace("any", *, *, 0)        = "any"
         StringUtils.replace("abaa", "a", null, -1) = "abaa"
         StringUtils.replace("abaa", "a", "", -1)   = "b"
         StringUtils.replace("abaa", "a", "z", 0)   = "abaa"
         StringUtils.replace("abaa", "a", "z", 1)   = "zbaa"
         StringUtils.replace("abaa", "a", "z", 2)   = "zbza"
         StringUtils.replace("abaa", "a", "z", -1)  = "zbzz"
         
        参数:
        text - text to search and replace in, may be null
        searchString - the String to search for, may be null
        replacement - the String to replace it with, may be null
        max - maximum number of values to replace, or -1 if no maximum
        返回:
        the text with any replacements processed, null if null String input
      • substringBetween

        public static java.lang.String substringBetween​(java.lang.String str,
                                                        java.lang.String tag)

        Gets the String that is nested in between two instances of the same String.

        A null input String returns null. A null tag returns null.

         StringUtils.substringBetween(null, *)            = null
         StringUtils.substringBetween("", "")             = ""
         StringUtils.substringBetween("", "tag")          = null
         StringUtils.substringBetween("tagabctag", null)  = null
         StringUtils.substringBetween("tagabctag", "")    = ""
         StringUtils.substringBetween("tagabctag", "tag") = "abc"
         
        参数:
        str - the String containing the substring, may be null
        tag - the String before and after the substring, may be null
        返回:
        the substring, null if no match
      • substringBetween

        public static java.lang.String substringBetween​(java.lang.String str,
                                                        java.lang.String open,
                                                        java.lang.String close)

        Gets the String that is nested in between two Strings. Only the first match is returned.

        A null input String returns null. A null open/close returns null (no match). An empty ("") open and close returns an empty string.

         StringUtils.substringBetween("wx[b]yz", "[", "]") = "b"
         StringUtils.substringBetween(null, *, *)          = null
         StringUtils.substringBetween(*, null, *)          = null
         StringUtils.substringBetween(*, *, null)          = null
         StringUtils.substringBetween("", "", "")          = ""
         StringUtils.substringBetween("", "", "]")         = null
         StringUtils.substringBetween("", "[", "]")        = null
         StringUtils.substringBetween("yabcz", "", "")     = ""
         StringUtils.substringBetween("yabcz", "y", "z")   = "abc"
         StringUtils.substringBetween("yabczyabcz", "y", "z")   = "abc"
         
        参数:
        str - the String containing the substring, may be null
        open - the String before the substring, may be null
        close - the String after the substring, may be null
        返回:
        the substring, null if no match
      • substringBefore

        public static java.lang.String substringBefore​(java.lang.String str,
                                                       java.lang.String separator)

        Gets the substring before the first occurrence of a separator. The separator is not returned.

        A null string input will return null. An empty ("") string input will return the empty string. A null separator will return the input string.

        If nothing is found, the string input is returned.

         StringUtils.substringBefore(null, *)      = null
         StringUtils.substringBefore("", *)        = ""
         StringUtils.substringBefore("abc", "a")   = ""
         StringUtils.substringBefore("abcba", "b") = "a"
         StringUtils.substringBefore("abc", "c")   = "ab"
         StringUtils.substringBefore("abc", "d")   = "abc"
         StringUtils.substringBefore("abc", "")    = ""
         StringUtils.substringBefore("abc", null)  = "abc"
         
        参数:
        str - the String to get a substring from, may be null
        separator - the String to search for, may be null
        返回:
        the substring before the first occurrence of the separator, null if null String input
      • substringAfter

        public static java.lang.String substringAfter​(java.lang.String str,
                                                      java.lang.String separator)

        Gets the substring after the first occurrence of a separator. The separator is not returned.

        A null string input will return null. An empty ("") string input will return the empty string. A null separator will return the empty string if the input string is not null.

        If nothing is found, the empty string is returned.

         StringUtils.substringAfter(null, *)      = null
         StringUtils.substringAfter("", *)        = ""
         StringUtils.substringAfter(*, null)      = ""
         StringUtils.substringAfter("abc", "a")   = "bc"
         StringUtils.substringAfter("abcba", "b") = "cba"
         StringUtils.substringAfter("abc", "c")   = ""
         StringUtils.substringAfter("abc", "d")   = ""
         StringUtils.substringAfter("abc", "")    = "abc"
         
        参数:
        str - the String to get a substring from, may be null
        separator - the String to search for, may be null
        返回:
        the substring after the first occurrence of the separator, null if null String input
      • substringBeforeLast

        public static java.lang.String substringBeforeLast​(java.lang.String str,
                                                           java.lang.String separator)

        Gets the substring before the last occurrence of a separator. The separator is not returned.

        A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the input string.

        If nothing is found, the string input is returned.

         StringUtils.substringBeforeLast(null, *)      = null
         StringUtils.substringBeforeLast("", *)        = ""
         StringUtils.substringBeforeLast("abcba", "b") = "abc"
         StringUtils.substringBeforeLast("abc", "c")   = "ab"
         StringUtils.substringBeforeLast("a", "a")     = ""
         StringUtils.substringBeforeLast("a", "z")     = "a"
         StringUtils.substringBeforeLast("a", null)    = "a"
         StringUtils.substringBeforeLast("a", "")      = "a"
         
        参数:
        str - the String to get a substring from, may be null
        separator - the String to search for, may be null
        返回:
        the substring before the last occurrence of the separator, null if null String input
      • substringAfterLast

        public static java.lang.String substringAfterLast​(java.lang.String str,
                                                          java.lang.String separator)

        Gets the substring after the last occurrence of a separator. The separator is not returned.

        A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the empty string if the input string is not null.

        If nothing is found, the empty string is returned.

         StringUtils.substringAfterLast(null, *)      = null
         StringUtils.substringAfterLast("", *)        = ""
         StringUtils.substringAfterLast(*, "")        = ""
         StringUtils.substringAfterLast(*, null)      = ""
         StringUtils.substringAfterLast("abc", "a")   = "bc"
         StringUtils.substringAfterLast("abcba", "b") = "a"
         StringUtils.substringAfterLast("abc", "c")   = ""
         StringUtils.substringAfterLast("a", "a")     = ""
         StringUtils.substringAfterLast("a", "z")     = ""
         
        参数:
        str - the String to get a substring from, may be null
        separator - the String to search for, may be null
        返回:
        the substring after the last occurrence of the separator, null if null String input