Here you can find the source of combineArray(String separator, String... stringArray)
Parameter | Description |
---|---|
separator | character set included between each part of the given array |
stringArray | array to combine |
public static String combineArray(String separator, String... stringArray)
//package com.java2s; /*/*ww w. ja v a2s . c o m*/ * 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 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(); } } }