Class StringUtils


  • public class StringUtils
    extends Object
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(String str)

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

         StringUtils.isEmpty(null)      = true
         StringUtils.isEmpty("")        = true
         StringUtils.isEmpty(" ")       = false
         StringUtils.isEmpty("bob")     = false
         StringUtils.isEmpty("  bob  ") = false
         

        NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().

        Parameters:
        str - the String to check, may be null
        Returns:
        true if the String is empty or null
      • isBlank

        public static boolean isBlank​(String str)

        Checks if a String is whitespace, empty ("") or null.

         StringUtils.isBlank(null)      = true
         StringUtils.isBlank("")        = true
         StringUtils.isBlank(" ")       = true
         StringUtils.isBlank("bob")     = false
         StringUtils.isBlank("  bob  ") = false
         
        Parameters:
        str - the String to check, may be null
        Returns:
        true if the String is null, empty or whitespace
      • join

        public static String join​(Object[] array,
                                  String separator)

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

        No delimiter is added before or after the list. A null separator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)                = null
         StringUtils.join([], *)                  = ""
         StringUtils.join([null], *)              = ""
         StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
         StringUtils.join(["a", "b", "c"], null)  = "abc"
         StringUtils.join(["a", "b", "c"], "")    = "abc"
         StringUtils.join([null, "", "a"], ',')   = ",,a"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use, null treated as ""
        Returns:
        the joined String, null if null array input
      • join

        public static String join​(Collection strings,
                                  String delimiter)
        Joins a collection of string with a given delimiter.
        Parameters:
        strings - The collection of strings to join.
        delimiter - The delimiter to use to join them.
        Returns:
        The string built by joining the string with the delimiter.
      • split

        public static List<String> split​(String str,
                                         char separatorChar)

        Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.

        The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.

        A null input String returns null.

         StringUtils.split(null, *)         = null
         StringUtils.split("", *)           = []
         StringUtils.split("a.b.c", '.')    = ["a", "b", "c"]
         StringUtils.split("a..b.c", '.')   = ["a", "b", "c"]
         StringUtils.split("a:b:c", '.')    = ["a:b:c"]
         StringUtils.split("a b c", ' ')    = ["a", "b", "c"]
         
        Parameters:
        str - the String to parse, may be null
        separatorChar - the character used as the delimiter
        Returns:
        an list of parsed Strings, null if null String input