Class StringUtils


  • public final class StringUtils
    extends java.lang.Object
    Utility methods to build a separated list from a given set (not java.util.Set) of inputs and return that list as a string or append it to an existing StringBuilder. If the given set is null or empty, an empty string will be returned.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void join​(java.lang.Iterable<java.lang.String> iterable, char separator, java.lang.StringBuilder sb)
      Joins the elements of an iterable with the specified separator and appends the result to the given StringBuilder.
      static <T> void join​(java.lang.Iterable<T> iterable, char separator, java.util.function.Function<T,​java.lang.String> function, java.lang.StringBuilder sb)
      Joins the elements of an iterable using the specified separator and function, and appends the result to the given StringBuilder.
      static java.lang.String join​(java.lang.String[] array)
      Joins the elements of a string array with a comma separator.
      static void join​(java.lang.String[] array, char separator, java.lang.StringBuilder sb)
      Joins the elements of a string array with the specified separator and appends the result to the given StringBuilder.
      static java.lang.String join​(java.lang.String a, java.lang.String b)
      Joins two strings with a comma separator.
      static java.lang.String join​(java.util.Collection<java.lang.String> collection)
      Joins the elements of a collection with a comma separator.
      static java.lang.String join​(java.util.Collection<java.lang.String> collection, char separator)
      Joins the elements of a collection with the specified separator.
      static <T> void join​(T[] array, char separator, java.util.function.Function<T,​java.lang.String> function, java.lang.StringBuilder sb)
      Joins the elements of an array using the specified separator and function, and appends the result to the given StringBuilder.
      static java.lang.String[] splitCommaSeparated​(java.lang.String s)
      Splits a comma-separated string into an array of String values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • join

        public static java.lang.String join​(java.lang.String a,
                                            java.lang.String b)
        Joins two strings with a comma separator.
        Parameters:
        a - the first string
        b - the second string
        Returns:
        the joined string
      • join

        public static java.lang.String join​(java.lang.String[] array)
        Joins the elements of a string array with a comma separator.
        Parameters:
        array - the array of strings to join
        Returns:
        the joined string
      • join

        public static void join​(java.lang.String[] array,
                                char separator,
                                java.lang.StringBuilder sb)
        Joins the elements of a string array with the specified separator and appends the result to the given StringBuilder.
        Parameters:
        array - the array of strings to join
        separator - the separator character
        sb - the StringBuilder to append to
      • join

        public static java.lang.String join​(java.util.Collection<java.lang.String> collection)
        Joins the elements of a collection with a comma separator.
        Parameters:
        collection - the collection of strings to join
        Returns:
        the joined string
      • join

        public static java.lang.String join​(java.util.Collection<java.lang.String> collection,
                                            char separator)
        Joins the elements of a collection with the specified separator.
        Parameters:
        collection - the collection of strings to join
        separator - the separator character
        Returns:
        the joined string
      • join

        public static void join​(java.lang.Iterable<java.lang.String> iterable,
                                char separator,
                                java.lang.StringBuilder sb)
        Joins the elements of an iterable with the specified separator and appends the result to the given StringBuilder.
        Parameters:
        iterable - the iterable of strings to join
        separator - the separator character
        sb - the StringBuilder to append to
      • join

        public static <T> void join​(T[] array,
                                    char separator,
                                    java.util.function.Function<T,​java.lang.String> function,
                                    java.lang.StringBuilder sb)
        Joins the elements of an array using the specified separator and function, and appends the result to the given StringBuilder.
        Type Parameters:
        T - the element type
        Parameters:
        array - the array to join
        separator - the separator character
        function - the function to apply to each element
        sb - the StringBuilder to append to
      • join

        public static <T> void join​(java.lang.Iterable<T> iterable,
                                    char separator,
                                    java.util.function.Function<T,​java.lang.String> function,
                                    java.lang.StringBuilder sb)
        Joins the elements of an iterable using the specified separator and function, and appends the result to the given StringBuilder.
        Type Parameters:
        T - the element type
        Parameters:
        iterable - the iterable to join
        separator - the separator character
        function - the function to apply to each element
        sb - the StringBuilder to append to
      • splitCommaSeparated

        public static java.lang.String[] splitCommaSeparated​(java.lang.String s)
        Splits a comma-separated string into an array of String values. Whitespace around the commas is removed. Null or empty values will return a zero-element array.
        Parameters:
        s - The string to split by commas.
        Returns:
        An array of String values.