Java String Implode implode(String... strings)

Here you can find the source of implode(String... strings)

Description

"Implodes" an array of strings into one string.

License

Open Source License

Parameter

Parameter Description
strings The string to format.

Return

The imploded string.

Declaration


public static String implode(String... strings) 

Method Source Code

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

public class Main {
    /**/* w  w w . j av a  2 s.  c om*/
     * "Implodes" an array of strings into one string. Equivilant to java's join() method.
     * @param strings The string to format.
     * @return The imploded string.
     */

    public static String implode(String... strings) {
        return implode(strings, "");
    }

    /**
     * "Implodes" an array of strings into one string. Equivilant to java's join() method.
     * @param strings The string to format.
     * @param glue The string to insert between each index of the array.
     * @return The imploded string.
     */

    public static String implode(String[] strings, String glue) {

        String output = "";

        if (strings.length > 0) {
            StringBuilder sb = new StringBuilder();
            sb.append(strings[0]);
            for (int i = 1; i < strings.length; i++) {
                sb.append(glue);
                sb.append(strings);
            }
            output = sb.toString();
        }

        return output;

    }
}

Related

  1. implode(String glue, String[] pieces)
  2. implode(String glue, String[] strArray)
  3. implode(String glue, T[] array)
  4. implode(String separator, String... data)
  5. implode(String separator, String... data)
  6. implode(String[] args)
  7. implode(String[] arr_str, String pemisah)
  8. implode(String[] array, char delimiter)
  9. implode(String[] array, String glue)