Java String Array Combine combineSplit(int startIndex, String[] string, String separator)

Here you can find the source of combineSplit(int startIndex, String[] string, String separator)

Description

Combines a set of strings into a single string, separated by the given character set

License

Open Source License

Parameter

Parameter Description
startIndex index to begin the separation at, inclusive
string array to combine
separator character set included between each part of the given array

Return

the combined string

Declaration

@Deprecated
public static String combineSplit(int startIndex, String[] string, String separator) 

Method Source Code

//package com.java2s;
/*//from w w  w  .  ja v a2s.com
 * This file is part of Commodus.
 *
 * Commodus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Commodus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Commodus.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Combines a set of strings into a single string, separated by the given character set
     *
     * @param startIndex index to begin the separation at, inclusive
     * @param string     array to combine
     * @param separator  character set included between each part of the given array
     * @return the combined string
     * @deprecated use {@link #combineArray(int, String, String...)}
     */
    @Deprecated
    public static String combineSplit(int startIndex, String[] string, String separator) {
        return combineArray(startIndex, separator, string);
    }

    /**
     * Combines a set of strings into a single string, separated by the given character set
     *
     * @param separator   character set included between each part of the given array
     * @param stringArray array to combine
     * @return the combined string
     */
    public static String combineArray(String separator, String... stringArray) {
        return combineArray(0, separator, stringArray);
    }

    /**
     * Combines a set of strings into a single string, separated by the given character set
     *
     * @param startIndex  index to begin the separation at, inclusive
     * @param separator   character set included between each part of the given array
     * @param stringArray array to combine
     * @return the combined string
     */
    public static String combineArray(int startIndex, String separator, String... stringArray) {
        return combineArray(startIndex, stringArray.length, separator, stringArray);
    }

    /**
     * Combines a set of strings into a single string, separated by the given character set
     *
     * @param startIndex  index to begin the separation at, inclusive
     * @param endIndex    index to end the separation at, exclusive
     * @param separator   character set included between each part of the given array
     * @param stringArray array to combine
     * @return the combined string
     */
    public static String combineArray(int startIndex, int endIndex, String separator, String... stringArray) {
        if (stringArray == null || startIndex >= endIndex) {
            return "";
        } else {
            StringBuilder builder = new StringBuilder();
            for (int i = startIndex; i < endIndex; i++) {
                builder.append(stringArray[i]);
                builder.append(separator);
            }
            builder.delete(builder.length() - separator.length(), builder.length());
            return builder.toString();
        }
    }
}

Related

  1. combineArray(String[] str, int start, int end)
  2. combineArrays(String[] array1, String[] array2)
  3. combineSplit(final int startIndex, final String[] string, final String seperator)
  4. combineSplit(int startIndex, String[] string, String separator)
  5. combineSplit(int startIndex, String[] string, String separator)
  6. combineString(String[] strArr, String glue)
  7. combineStringArray(String[] array, String delim)
  8. combineStrings(Object... strings)
  9. combineStrings(Object[] list)