Java Array Implode implode(double[] array, String separator)

Here you can find the source of implode(double[] array, String separator)

Description

implode

License

Open Source License

Declaration

public static String implode(double[] array, String separator) 

Method Source Code


//package com.java2s;

import java.util.Arrays;

public class Main {
    public static String implode(double[] array, String separator) {
        StringBuffer out = new StringBuffer();
        boolean first = true;
        for (double v : array) {
            if (first) {
                first = false;/* www  .j  a  va  2 s.  co  m*/
            } else {
                out.append(separator);
            }
            out.append(v);
        }
        return out.toString();
    }

    public static String implode(Object[] values) {
        return implode(values, ", ");
    }

    public static String implode(Object[] values, Object separator) {
        return implode(Arrays.asList(values), separator);
    }

    public static final <T> String implode(Iterable<T> elements, Object separator) {
        String sepStr = separator.toString();
        StringBuilder out = new StringBuilder();
        boolean first = true;
        for (Object s : elements) {
            if (s == null) {
                continue;
            }

            if (first) {
                first = false;
            } else {
                out.append(sepStr);
            }
            out.append(s);
        }
        return out.toString();
    }

    public static final String implode(Iterable<?> strings) {
        return implode(strings, ", ");
    }
}

Related

  1. implode(final String[] array, final String delim)
  2. implode(final String[] pStrArray)
  3. implode(Object[] array, String separator)
  4. implode(Object[] ary, String delim)