Java Array to String arrayToString(Object[] array, String separator)

Here you can find the source of arrayToString(Object[] array, String separator)

Description

array To String

License

Open Source License

Declaration

public static String arrayToString(Object[] array, String separator) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    public static String arrayToString(Object[] array, String separator) {
        if (array == null || array.length == 0) {
            return "";
        }/*  www.  ja  v a 2  s. c  o  m*/

        StringBuffer s = new StringBuffer(32 * array.length);

        s.append(array[0]);

        for (int i = 1; i < array.length; i++) {
            s.append(separator).append(array[i]);
        }

        return s.toString();
    }

    public static String arrayToString(List<?> array, String separator) {
        if (array == null || array.size() == 0) {
            return "";
        }

        StringBuffer s = new StringBuffer(32 * array.size());

        s.append(array.get(0));
        for (int i = 1; i < array.size(); i++) {
            s.append(separator).append(array.get(i));
        }

        return s.toString();
    }

    public static String arrayToString(int[] array, String separator) {
        if (array == null || array.length == 0) {
            return "";
        }

        StringBuffer s = new StringBuffer(32 * array.length);

        s.append(array[0]);

        for (int i = 1; i < array.length; i++) {
            s.append(separator).append(array[i]);
        }

        return s.toString();
    }

    public static String arrayToString(double[] array, String separator) {
        if (array == null || array.length == 0) {
            return "";
        }

        StringBuffer s = new StringBuffer(32 * array.length);

        s.append(array[0]);

        for (int i = 1; i < array.length; i++) {
            s.append(separator).append(array[i]);
        }

        return s.toString();
    }

    public static String arrayToString(String[] stringArray, String OutputDelimiter) {
        int linenum = 0;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < stringArray.length; i++) {
            linenum++;
            if (linenum == 1) {
                sb.append(stringArray[i]);
            } else {
                sb.append(OutputDelimiter);
                sb.append(stringArray[i]);
            }
        }
        return sb.toString();
    }
}

Related

  1. ArrayToString(Object[] array, String conv)
  2. arrayToString(Object[] array, String delim, int maxValues, boolean useBrackets)
  3. arrayToString(Object[] array, String prefix, String suffix, String separator)
  4. arrayToString(Object[] array, String sep)
  5. arrayToString(Object[] array, String separator)
  6. arrayToString(Object[] array, String split)
  7. arrayToString(Object[] ary)
  8. arrayToString(Object[] list)
  9. arrayToString(Object[] objects)