Java Array to String arrayToStringWithPrefix(T[] array, String splitter, String prefix)

Here you can find the source of arrayToStringWithPrefix(T[] array, String splitter, String prefix)

Description

array To String With Prefix

License

Apache License

Declaration

public static <T> String arrayToStringWithPrefix(T[] array,
            String splitter, String prefix) 

Method Source Code

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

public class Main {
    public static <T> String arrayToStringWithPrefix(T[] array,
            String splitter, String prefix) {
        return prefix + arrayToString(array, splitter + prefix);
    }/*w  w w.j  a va  2  s . c  om*/

    public static <T> String arrayToString(T[] array, String splitter) {
        if (array == null)
            return null;
        if (array.length == 0)
            return "";

        StringBuilder stringBuilder = new StringBuilder(array[0].toString());
        for (int i = 1; i < array.length; i++) {
            stringBuilder.append(splitter);
            stringBuilder.append(array[i]);
        }
        return stringBuilder.toString();
    }

    public static <T> String arrayToString(T[] array) {
        return arrayToString(array, ", ");
    }
}

Related

  1. arrayToStringArray(boolean[] values)
  2. arrayToStringDelimited(final String[] array, final String delimiter)
  3. arrayToStringNullable(String[] a)
  4. arrayToStrings(String[] s, String delimiter)
  5. arrayToStringWithDifferenceOrientedFormat(double[] values, int minDigits)
  6. asString(final String[] array)
  7. asString(int[] objects, String separator)
  8. asString(String[] arrayParameter)
  9. asString(T[] objects)