Java Array Implode implode(final String[] pStrArray)

Here you can find the source of implode(final String[] pStrArray)

Description

implode

License

Open Source License

Declaration

public static String implode(final String[] pStrArray) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;

public class Main {
    /** line separator. */
    private static final String LINE_SEPARATOR = System.lineSeparator();

    public static String implode(final String[] pStrArray) {
        return implode(pStrArray, "\t");
    }//ww  w.  j  a v a2s. c  o m

    public static String implode(final Object[] pieces, final String glue) {
        final StringBuilder buf = new StringBuilder(110);
        for (int i = 0; i < pieces.length; i++) {
            if (0 < i) {
                buf.append(glue);
            }
            buf.append(pieces[i].toString());
        }
        return buf.toString();
    }

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

    public static String implode(final Iterable<?> pieces, final String glue) {
        if (pieces == null) {
            return "";
        }
        final StringBuilder resBuf = new StringBuilder(100);
        final Iterator<?> iter = pieces.iterator();
        resBuf.append(iter.next().toString());
        while (iter.hasNext()) {
            resBuf.append(glue);
            resBuf.append(iter.next().toString());
        }
        return resBuf.toString();
    }
}

Related

  1. implode(double[] array, String separator)
  2. implode(final String[] array, final String delim)
  3. implode(Object[] array, String separator)
  4. implode(Object[] ary, String delim)
  5. implode(String delim, Object[] objects)
  6. implode(String delim, String[] args)