Java String Implode implode(String glue, String[] pieces)

Here you can find the source of implode(String glue, String[] pieces)

Description

join a 'pieces' string array to a string

License

Open Source License

Parameter

Parameter Description
glue String the source string
pieces String[] need to be appended string

Return

String

Declaration

public static String implode(String glue, String[] pieces) 

Method Source Code

//package com.java2s;

public class Main {
    /**// w ww  .  j a v a2 s . c o  m
     * join a 'pieces' string array to a string
     * 
     * @param glue String the source string
     * @param pieces String[] need to be appended string
     * @return String
     */
    public static String implode(String glue, String[] pieces) {
        return implode(glue, pieces, 0);
    }

    /**
     * join a 'pieces' string array to a string
     * 
     * @param glue String the source string
     * @param pieces String[] need to be appended string
     * @param beginIndex int the start index to implode (begin at 0)
     * @return String
     */
    public static String implode(String glue, String[] pieces, int beginIndex) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < pieces.length; i++) {
            if (beginIndex != -1 && i < beginIndex) {
                continue;
            }
            if (sb.length() > 0) {
                sb.append(glue);
            }
            sb.append(pieces[i]);
        }
        return sb.toString();
    }
}

Related

  1. implode(Object[] source, String delimiter)
  2. implode(String delim, Object[] array)
  3. implode(String delimiter, String[] strings)
  4. implode(String glue, String... parts)
  5. implode(String glue, String[] inputArray)
  6. implode(String glue, String[] pieces)
  7. implode(String glue, String[] strArray)
  8. implode(String glue, T[] array)
  9. implode(String separator, String... data)