Class StringBuilderJoiner


  • public class StringBuilderJoiner
    extends java.lang.Object
    Utility class similar to StringJoiner / String.join(CharSequence, Iterable) / Collectors.joining(CharSequence) that does not create intermediary Strings but appends all parts to a preexisting StringBuilder.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_SEPARATOR  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void join​(java.lang.StringBuilder sb, java.lang.Iterable<?> iterable)
      Appends the elements of the provided Iterable to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ".
      static void join​(java.lang.StringBuilder sb, java.lang.Iterable<?> iterable, java.lang.String separator)
      Appends the elements of the provided Iterable to the given StringBuilder, separated by the given separator.
      static <T> void join​(java.lang.StringBuilder sb, java.lang.Iterable<T> iterable, java.lang.String separator, java.util.function.Consumer<? super T> singleItemAppender)
      Appends the elements of the provided Iterable, converted to String with the given toString Function, to the given StringBuilder, separated by the given separator.
      static <T> void join​(java.lang.StringBuilder sb, java.lang.Iterable<T> iterable, java.util.function.Consumer<? super T> singleItemAppender)
      Appends the elements of the provided Iterable, converted to String with the given toString Function, to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ".
      static void join​(java.lang.StringBuilder sb, java.lang.Object[] objectArray)
      Appends the elements of the provided array to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ".
      static <T> void join​(java.lang.StringBuilder sb, T[] objectArray, java.util.function.Consumer<? super T> singleItemAppender)
      Appends the elements of the provided array, converted to String with the given toString Function, to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ".
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_SEPARATOR

        public static final java.lang.String DEFAULT_SEPARATOR
        See Also:
        Constant Field Values
    • Method Detail

      • join

        public static final void join​(java.lang.StringBuilder sb,
                                      java.lang.Iterable<?> iterable,
                                      java.lang.String separator)
        Appends the elements of the provided Iterable to the given StringBuilder, separated by the given separator. No delimiter is added before or after the list.
        Parameters:
        sb - the StringBuilder to which the values will be appended
        iterable - the Collection of values to join together, may be null
        separator - the separator to use, null treated as ""
      • join

        public static final void join​(java.lang.StringBuilder sb,
                                      java.lang.Iterable<?> iterable)
        Appends the elements of the provided Iterable to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ". No delimiter is added before or after the list.
        Parameters:
        sb - the StringBuilder to which the values will be appended
        iterable - the Collection of values to join together, may be null
      • join

        public static final void join​(java.lang.StringBuilder sb,
                                      java.lang.Object[] objectArray)
        Appends the elements of the provided array to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ". No delimiter is added before or after the list.
        Parameters:
        sb - the StringBuilder to which the values will be appended
        objectArray - the array of values to join together, may be null
      • join

        public static final <T> void join​(java.lang.StringBuilder sb,
                                          java.lang.Iterable<T> iterable,
                                          java.util.function.Consumer<? super T> singleItemAppender)
        Appends the elements of the provided Iterable, converted to String with the given toString Function, to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ". No delimiter is added before or after the list.
        Parameters:
        sb - the StringBuilder to which the values will be appended
        iterable - the Collection of values to join together, may be null
        singleItemAppender - a Consumer that takes a single element to append it with multiple calls to StringBuilder.append(String)
      • join

        public static final <T> void join​(java.lang.StringBuilder sb,
                                          T[] objectArray,
                                          java.util.function.Consumer<? super T> singleItemAppender)
        Appends the elements of the provided array, converted to String with the given toString Function, to the given StringBuilder, separated by the DEFAULT_SEPARATOR ", ". No delimiter is added before or after the list.
        Parameters:
        sb - the StringBuilder to which the values will be appended
        objectArray - the array of values to join together, may be null
        singleItemAppender - a Consumer that takes a single element to append it with multiple calls to StringBuilder.append(String)
      • join

        public static final <T> void join​(java.lang.StringBuilder sb,
                                          java.lang.Iterable<T> iterable,
                                          java.lang.String separator,
                                          java.util.function.Consumer<? super T> singleItemAppender)
        Appends the elements of the provided Iterable, converted to String with the given toString Function, to the given StringBuilder, separated by the given separator. No delimiter is added before or after the list.
        Parameters:
        sb - the StringBuilder to which the values will be appended
        iterable - the Collection of values to join together, may be null
        separator - the separator to use, null treated as ""
        singleItemAppender - a Consumer that takes a single element to append it with multiple calls to StringBuilder.append(String)