Java Array Append appendArray(StringBuilder sb, T[] array, String delimiter)

Here you can find the source of appendArray(StringBuilder sb, T[] array, String delimiter)

Description

Appends all elements of array to buffer, separated by delimiter

License

LGPL

Parameter

Parameter Description
T Type of elements stored in <code>array</code>
sb StringBuilder to be modified
array Array of elements
delimiter Delimiter to separate elements

Return

Modified sb to allow chaining

Declaration

public static <T> StringBuilder appendArray(StringBuilder sb, T[] array, String delimiter) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//from   ww w  .j  a v a2s . co  m
     * Appends all elements of <code>array</code> to buffer, separated by delimiter
     * @param <T> Type of elements stored in <code>array</code>
     * @param sb StringBuilder to be modified
     * @param array Array of elements
     * @param delimiter Delimiter to separate elements
     * @return Modified <code>sb</code> to allow chaining
     */
    public static <T> StringBuilder appendArray(StringBuilder sb, T[] array, String delimiter) {

        boolean firstRun = true;

        for (T elem : array) {
            if (!firstRun)
                sb.append(delimiter);
            else
                firstRun = false;

            sb.append(elem.toString());
        }

        return sb;

    }
}

Related

  1. appendArray(Object[] arr, Object obj)
  2. appendArray(Object[] array1, Object[] array2)
  3. appendArray(String[] A, String... B)
  4. appendArray(StringBuilder bld, Object[] array, String sep)
  5. appendArray(StringBuilder sb, int[] arr)
  6. appendArrays(byte[] in1, byte[] in2)
  7. appendArrays(final byte[] firstArray, final byte[] secondArray)
  8. ARRAY_AddValueToArray(int new_value, int[] array)
  9. arrayAppend(byte[] original, byte[] append)