Here you can find the source of implode(String[] array, String separator)
Parameter | Description |
---|---|
array | The array containing the strings to connect |
separator | The separator between the connected elements |
public static String implode(String[] array, String separator)
//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); } }