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

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

Description

Connects all elements of array to a string.

License

Open Source License

Parameter

Parameter Description
array The array containing the strings to connect
separator The separator between the connected elements

Return

All array elements connected to a string.

Declaration

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

Method Source Code

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

public class Main {
    /**/*from  w  w w  .  j  a v  a  2 s.co  m*/
     * Connects all array elements to a string.
     * 
     * @param array The array containing the strings to connect
     * @param separator The separator between the connected elements
     * @param start Start index in array
     * @param stop Stop index in array
     * @param skipEmpty If {@code true} empty array elements are ignored
     * @return All array elements in the specified range connected to a string.
     */
    public static String implode(String[] array, String separator, int start, int stop, boolean skipEmpty) {
        StringBuilder builder = new StringBuilder();

        for (int i = start; i < stop; i++) {
            if (skipEmpty && array[i].isEmpty())
                continue;

            builder.append(array[i]);

            if (i < stop - 1) {
                builder.append(separator);
            }
        }

        return builder.toString();
    }

    /**
     * Connects all elements of {@code array} to a string. <br>
     * Calling this method has the same effect as {@code implode(array, splitter, 0, array.length, false)}.
     * 
     * @param array The array containing the strings to connect
     * @param separator The separator between the connected elements
     * @return All array elements connected to a string.
     */
    public static String implode(String[] array, String separator) {
        return implode(array, separator, 0, array.length, false);
    }
}

Related

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