Class StringUtils

java.lang.Object
org.apache.tomcat.util.buf.StringUtils

public final class StringUtils extends 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

    Modifier and Type
    Method
    Description
    static void
    join(Iterable<String> iterable, char separator, StringBuilder sb)
    Joins the elements of an iterable with the specified separator and appends the result to the given StringBuilder.
    static <T> void
    join(Iterable<T> iterable, char separator, Function<T,String> function, StringBuilder sb)
    Joins the elements of an iterable using the specified separator and function, and appends the result to the given StringBuilder.
    static String
    join(String[] array)
    Joins the elements of a string array with a comma separator.
    static void
    join(String[] array, char separator, StringBuilder sb)
    Joins the elements of a string array with the specified separator and appends the result to the given StringBuilder.
    static String
    Joins two strings with a comma separator.
    static String
    join(Collection<String> collection)
    Joins the elements of a collection with a comma separator.
    static String
    join(Collection<String> collection, char separator)
    Joins the elements of a collection with the specified separator.
    static <T> void
    join(T[] array, char separator, Function<T,String> function, StringBuilder sb)
    Joins the elements of an array using the specified separator and function, and appends the result to the given StringBuilder.
    static String[]
    Splits a comma-separated string into an array of String values.

    Methods inherited from class Object

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

    • join

      public static String join(String a, 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 String join(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(String[] array, char separator, 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 String join(Collection<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 String join(Collection<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(Iterable<String> iterable, char separator, 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, Function<T,String> function, 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(Iterable<T> iterable, char separator, Function<T,String> function, 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 String[] splitCommaSeparated(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.