Java String Implode implode(String glue, T[] array)

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

Description

implode

License

Apache License

Declaration

public static <T> String implode(String glue, T[] array) 

Method Source Code

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

public class Main {
    public static <T> String implode(String glue, T[] array) {
        // array is empty, return empty string
        if (array == null || array.length == 0) {
            return "";
        }//w w w.j a va 2s.  c  o  m

        // init the builder with the first element
        StringBuilder sb = new StringBuilder();
        sb.append(array[0]);

        // concat each element
        // begin at 1 to avoid duplicating first element
        for (int i = 1; i < array.length; i++) {
            sb.append(glue).append(array[i]);
        }

        // return the result
        return sb.toString();
    }
}

Related

  1. implode(String glue, String... parts)
  2. implode(String glue, String[] inputArray)
  3. implode(String glue, String[] pieces)
  4. implode(String glue, String[] pieces)
  5. implode(String glue, String[] strArray)
  6. implode(String separator, String... data)
  7. implode(String separator, String... data)
  8. implode(String... strings)
  9. implode(String[] args)