Java Array to Delimited String arrayToDelimitedString(T[] array, String left, String delimiter, String right)

Here you can find the source of arrayToDelimitedString(T[] array, String left, String delimiter, String right)

Description

array To Delimited String

License

Apache License

Declaration

public static <T> String arrayToDelimitedString(T[] array, String left,
            String delimiter, String right) 

Method Source Code

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

public class Main {
    public static <T> String arrayToDelimitedString(T[] array, String left,
            String delimiter, String right) {
        return arrayToDelimitedString(array, 0, array.length, left,
                delimiter, right);//from w  w w .  j  a v  a  2s .c  o m
    }

    public static <T> String arrayToDelimitedString(T[] array, int offset,
            int length, String delimiter) {
        return arrayToDelimitedString(array, offset, length, "", delimiter,
                "");
    }

    public static <T> String arrayToDelimitedString(T[] array,
            String delimiter) {
        return arrayToDelimitedString(array, 0, array.length, "",
                delimiter, "");
    }

    public static <T> String arrayToDelimitedString(T[] array, int offset,
            int length, String left, String delimiter, String right) {
        StringBuilder buf = new StringBuilder();
        for (int i = offset; i < offset + length - 1; i++) {
            buf.append(left).append(array[i]).append(right)
                    .append(delimiter);
        }
        if (length > 0)
            buf.append(left).append(array[offset + length - 1])
                    .append(right);
        return buf.toString();
    }
}

Related

  1. arrayToCommaString(int[] array)
  2. arrayToDelimitedString(Object[] arr, String delim)
  3. arrayToDelimitedString(Object[] arr, String delim)
  4. arrayToDelimitedString(Object[] arr, String delim)
  5. arrayToDelimitedString(String[] values, String delimiter)
  6. arrayToReadableString(String[] array)
  7. arrayToTabSeparatedString( final String[] values)
  8. arrayToText(String[] values, String delimiter)