Java String Implode implode(String[] stringsArr, String glue)

Here you can find the source of implode(String[] stringsArr, String glue)

Description

Concatenate strings of given array glued by given delimiter

License

Apache License

Parameter

Parameter Description
stringsArr Array of strings
glue Glue in between concatenated strings

Return

String All items of stringsArr concatenated with glue

Declaration

public static String implode(String[] stringsArr, String glue) 

Method Source Code

//package com.java2s;
/*/*from  www  .  j av a 2  s .c o  m*/
 * Copyright 2011-2015 Kay Stenschke
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Concatenate strings of given array glued by given delimiter
     *
     * @param   stringsArr  Array of strings
     * @param   glue        Glue in between concatenated strings
     * @return  String      All items of stringsArr concatenated with glue
     */
    public static String implode(String[] stringsArr, String glue) {
        String out = "";

        for (int i = 0; i < stringsArr.length; i++) {
            out += (i != 0 ? glue : "") + stringsArr[i];
        }

        return out;
    }
}

Related

  1. implode(String[] array, String separator)
  2. implode(String[] data, String delimiter)
  3. implode(String[] input)
  4. implode(String[] segments, String delimiter)
  5. implode(String[] strings, String delimiter)
  6. implode(StringBuilder sbuf, Object[] data, String separator)
  7. implode(T[] array, String delim)
  8. implodeParams(Object[] params)
  9. implodeString(String[] strings, String seperator)