类 StringUtils


  • public class StringUtils
    extends java.lang.Object
    string util.
    作者:
    Nacos, zzq
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static java.lang.String COMMA  
      static java.lang.String DOT  
      static java.lang.String EMPTY  
      private static int INDEX_NOT_FOUND  
      static java.lang.String LF  
    • 构造器概要

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

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static boolean contains​(java.lang.CharSequence str, java.lang.CharSequence searchStr)
      Checks if CharSequence contains a search CharSequence.
      static boolean containsIgnoreCase​(java.lang.CharSequence str, java.lang.CharSequence searchStr)
      Checks if CharSequence contains a search CharSequence irrespective of case, handling null.
      static java.lang.String defaultIfEmpty​(java.lang.String str, java.lang.String defaultStr)
      Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value of defaultStr.
      static java.lang.String deleteWhitespace​(java.lang.String str)
      Deletes all whitespaces from a String as defined by Character.isWhitespace(char).
      static boolean equals​(java.lang.String str1, java.lang.String str2)
      Compares two CharSequences, returning true if they represent equal sequences of characters.
      static boolean equalsIgnoreCase​(java.lang.String str1, java.lang.String str2)
      Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.
      static java.lang.String escapeJavaScript​(java.lang.String str)  
      private static void escapeJavaStyleString​(java.io.Writer out, java.lang.String str, boolean escapeSingleQuote, boolean escapeForwardSlash)  
      private static java.lang.String escapeJavaStyleString​(java.lang.String str, boolean escapeSingleQuotes, boolean escapeForwardSlash)  
      private static java.lang.String hex​(char ch)  
      static boolean isAnyBlank​(java.lang.CharSequence... css)
      Checks if any one of the CharSequences are blank ("") or null and not whitespace only..
      static boolean isBlank​(java.lang.CharSequence cs)
      Checks if a string is empty (""), null and whitespace only.
      static boolean isEmpty​(java.lang.String str)
      Checks if a str is empty ("") or null.
      static boolean isNoneBlank​(java.lang.CharSequence... css)
      Checks if none of the CharSequences are blank ("") or null and whitespace only..
      static boolean isNotBlank​(java.lang.String str)
      Checks if a string is not empty (""), not null and not whitespace only.
      static boolean isNotEmpty​(java.lang.String str)
      Checks if a str is not empty ("") or not null.
      static java.lang.String join​(java.util.Collection collection, java.lang.String separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static java.lang.String newStringForUtf8​(byte[] bytes)
      Create a string with encoding format as utf8.
      static java.lang.String[] split​(java.lang.String str, java.lang.String separatorChars)
      Splits the provided text into an array with a maximum length, separators specified.
      static boolean startsWith​(java.lang.CharSequence str, java.lang.CharSequence prefix)
      Check if a CharSequence starts with a specified prefix.
      private static boolean startsWith​(java.lang.CharSequence str, java.lang.CharSequence prefix, boolean ignoreCase)
      Check if a CharSequence starts with a specified prefix (optionally case insensitive).
      static boolean startsWithIgnoreCase​(java.lang.CharSequence str, java.lang.CharSequence prefix)
      Case insensitive check if a CharSequence starts with a specified prefix.
      static java.lang.String substringBetween​(java.lang.String str, java.lang.String open, java.lang.String close)
      Substring between two index.
      static java.lang.String trim​(java.lang.String str)
      Removes control characters (char <= 32) from both ends of this String, handling null by returning null.
      • 从类继承的方法 java.lang.Object

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

      • DOT

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

        private static final int INDEX_NOT_FOUND
        另请参阅:
        常量字段值
      • COMMA

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

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

        public static final java.lang.String LF
        另请参阅:
        常量字段值
    • 构造器详细资料

      • StringUtils

        public StringUtils()
    • 方法详细资料

      • newStringForUtf8

        public static java.lang.String newStringForUtf8​(byte[] bytes)

        Create a string with encoding format as utf8.

        参数:
        bytes - the bytes that make up the string
        返回:
        created string
      • isBlank

        public static boolean isBlank​(java.lang.CharSequence cs)

        Checks if a string is empty (""), null and whitespace only.

        参数:
        cs - the string to check
        返回:
        true if the string is empty and null and whitespace
      • isNotBlank

        public static boolean isNotBlank​(java.lang.String str)

        Checks if a string is not empty (""), not null and not whitespace only.

        参数:
        str - the string to check, may be null
        返回:
        true if the string is not empty and not null and not whitespace
      • isNotEmpty

        public static boolean isNotEmpty​(java.lang.String str)

        Checks if a str is not empty ("") or not null.

        参数:
        str - the str to check, may be null
        返回:
        true if the str is not empty or not null
      • isEmpty

        public static boolean isEmpty​(java.lang.String str)

        Checks if a str is empty ("") or null.

        参数:
        str - the str to check, may be null
        返回:
        true if the str is empty or null
      • defaultIfEmpty

        public static java.lang.String defaultIfEmpty​(java.lang.String str,
                                                      java.lang.String defaultStr)

        Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value of defaultStr.

        参数:
        str - the CharSequence to check, may be null
        defaultStr - the default CharSequence to return if the input is empty ("") or null, may be null
        返回:
        the passed in CharSequence, or the default
      • equals

        public static boolean equals​(java.lang.String str1,
                                     java.lang.String str2)

        Compares two CharSequences, returning true if they represent equal sequences of characters.

        参数:
        str1 - the first string, may be null
        str2 - the second string, may be null
        返回:
        true if the string are equal (case-sensitive), or both null
        另请参阅:
        Object.equals(Object)
      • trim

        public static java.lang.String trim​(java.lang.String str)

        Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

        参数:
        str - the String to be trimmed, may be null
        返回:
        the trimmed string, null if null String input
      • substringBetween

        public static java.lang.String substringBetween​(java.lang.String str,
                                                        java.lang.String open,
                                                        java.lang.String close)
        Substring between two index.
        参数:
        str - string
        open - start index to sub
        close - end index to sub
        返回:
        substring
      • join

        public static java.lang.String join​(java.util.Collection collection,
                                            java.lang.String separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        参数:
        collection - the Collection of values to join together, may be null
        separator - the separator string to use
        返回:
        the joined String, null if null array input
      • escapeJavaScript

        public static java.lang.String escapeJavaScript​(java.lang.String str)
      • escapeJavaStyleString

        private static java.lang.String escapeJavaStyleString​(java.lang.String str,
                                                              boolean escapeSingleQuotes,
                                                              boolean escapeForwardSlash)
      • escapeJavaStyleString

        private static void escapeJavaStyleString​(java.io.Writer out,
                                                  java.lang.String str,
                                                  boolean escapeSingleQuote,
                                                  boolean escapeForwardSlash)
                                           throws java.io.IOException
        抛出:
        java.io.IOException
      • hex

        private static java.lang.String hex​(char ch)
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(java.lang.CharSequence str,
                                                 java.lang.CharSequence searchStr)
        Checks if CharSequence contains a search CharSequence irrespective of case, handling null. Case-insensitivity is defined as by String.equalsIgnoreCase(String).

        A null CharSequence will return false.

        参数:
        str - the CharSequence to check, may be null
        searchStr - the CharSequence to find, may be null
        返回:
        true if the CharSequence contains the search CharSequence irrespective of case or false if not or null string input
      • contains

        public static boolean contains​(java.lang.CharSequence str,
                                       java.lang.CharSequence searchStr)
        Checks if CharSequence contains a search CharSequence.
        参数:
        str - the CharSequence to check, may be null
        searchStr - the CharSequence to find, may be null
        返回:
        true if the CharSequence contains the search CharSequence
      • isNoneBlank

        public static boolean isNoneBlank​(java.lang.CharSequence... css)

        Checks if none of the CharSequences are blank ("") or null and whitespace only..

        参数:
        css - the CharSequences to check, may be null or empty
        返回:
        true if none of the CharSequences are blank or null or whitespace only
      • isAnyBlank

        public static boolean isAnyBlank​(java.lang.CharSequence... css)

        Checks if any one of the CharSequences are blank ("") or null and not whitespace only..

        参数:
        css - the CharSequences to check, may be null or empty
        返回:
        true if any of the CharSequences are blank or null or whitespace only
      • startsWith

        public static boolean startsWith​(java.lang.CharSequence str,
                                         java.lang.CharSequence prefix)

        Check if a CharSequence starts with a specified prefix.

        nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive.

        参数:
        str - the CharSequence to check, may be null
        prefix - the prefix to find, may be null
        返回:
        true if the CharSequence starts with the prefix, case sensitive, or both null
        另请参阅:
        String.startsWith(String)
      • startsWith

        private static boolean startsWith​(java.lang.CharSequence str,
                                          java.lang.CharSequence prefix,
                                          boolean ignoreCase)

        Check if a CharSequence starts with a specified prefix (optionally case insensitive).

        参数:
        str - the CharSequence to check, may be null
        prefix - the prefix to find, may be null
        ignoreCase - indicates whether the compare should ignore case (case insensitive) or not.
        返回:
        true if the CharSequence starts with the prefix or both null
        另请参阅:
        String.startsWith(String)
      • startsWithIgnoreCase

        public static boolean startsWithIgnoreCase​(java.lang.CharSequence str,
                                                   java.lang.CharSequence prefix)

        Case insensitive check if a CharSequence starts with a specified prefix.

        nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case insensitive.

        参数:
        str - the CharSequence to check, may be null
        prefix - the prefix to find, may be null
        返回:
        true if the CharSequence starts with the prefix, case insensitive, or both null
        另请参阅:
        String.startsWith(String)
      • deleteWhitespace

        public static java.lang.String deleteWhitespace​(java.lang.String str)

        Deletes all whitespaces from a String as defined by Character.isWhitespace(char).

        参数:
        str - the String to delete whitespace from, may be null
        返回:
        the String without whitespaces, null if null String input
      • equalsIgnoreCase

        public static boolean equalsIgnoreCase​(java.lang.String str1,
                                               java.lang.String str2)

        Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

        参数:
        str1 - the first string, may be null
        str2 - the second string, may be null
        返回:
        true if the string are equal, case insensitive, or both null
      • split

        public static java.lang.String[] split​(java.lang.String str,
                                               java.lang.String separatorChars)
        Splits the provided text into an array with a maximum length, separators specified. If separatorChars is empty, divide by blank.
        参数:
        str - the String to parse, may be null
        返回:
        an array of parsed Strings