Java String Implode implode(String delim, Object[] array)

Here you can find the source of implode(String delim, Object[] array)

Description

Joins array elements in a String.

License

Open Source License

Parameter

Parameter Description
delim Delimiter between each array element
array Array of elements

Return

String

Declaration

public static String implode(String delim, Object[] array) 

Method Source Code

//package com.java2s;
/* /*from   w w w.  j  a  v a2 s . com*/
 * Copyright (C) 2014 Institute for Bioinformatics and Systems Biology, University Giessen, Germany
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
    * Joins array elements in a String.
    * @param delim Delimiter between each array element
    * @param array Array of elements
    * @return String
    */
    public static String implode(String delim, Object[] array) {
        String asImplodedString;
        if (array.length == 0) {
            asImplodedString = "";
        } else {
            StringBuilder sb = new StringBuilder();
            sb.append(array[0]);
            for (int i = 1; i < array.length; i++) {
                sb.append(delim);
                sb.append(array[i]);
            }
            asImplodedString = sb.toString();
        }
        return asImplodedString;
    }
}

Related

  1. implode(final String separator, final Iterable data)
  2. implode(Object strarr[], String delim)
  3. implode(Object[] data, String delimiter)
  4. implode(Object[] elements, String delimiter)
  5. implode(Object[] source, String delimiter)
  6. implode(String delimiter, String[] strings)
  7. implode(String glue, String... parts)
  8. implode(String glue, String[] inputArray)
  9. implode(String glue, String[] pieces)