Here you can find the source of implode(String[] inputArray, String glueString)
Parameter | Description |
---|---|
inputArray | Array which contains strings |
glueString | String between each array element |
public static String implode(String[] inputArray, String glueString)
//package com.java2s; /*/*from w ww . j a v a 2 s. c o m*/ * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. * * Copyright (c) 2014, Gluu */ import java.util.*; public class Main { public static final String EMPTY_STRING = ""; /** * Method to join array elements of type string * * @param inputArray Array which contains strings * @param glueString String between each array element * @return String containing all array elements separated by glue string. */ public static String implode(String[] inputArray, String glueString) { String output = EMPTY_STRING; if (inputArray != null && inputArray.length > 0) { StringBuilder sb = new StringBuilder(); sb.append(inputArray[0]); for (int i = 1; i < inputArray.length; i++) { sb.append(glueString); sb.append(inputArray[i]); } output = sb.toString(); } return output; } /** * Method to join a list of elements of type string * * @param inputList List which contains strings * @param glueString String between each array element * @return String containing all array elements separated by glue string. */ public static String implode(List inputList, String glueString) { String output = EMPTY_STRING; if (inputList != null && !inputList.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append(inputList.get(0)); for (int i = 1; i < inputList.size(); i++) { sb.append(glueString); sb.append(inputList.get(i)); } output = sb.toString(); } return output; } }