Android String Array Join concatenate(String[] elements, String delimiter)

Here you can find the source of concatenate(String[] elements, String delimiter)

Description

concatenate

License

GNU General Public License

Declaration

public static String concatenate(String[] elements, String delimiter) 

Method Source Code

//package com.java2s;
/*/*from   www  . j  a  v  a 2 s. c  o  m*/
 * AndFHEM - Open Source Android application to control a FHEM home automation
 *  server.
 *
 *  Copyright (c) 2012, Matthias Klass or third-party contributors as
 *  indicated by the @author tags or express copyright attribution
 *  statements applied by the authors.  All third-party contributions are
 *  distributed under license by Red Hat Inc.
 *
 *  This copyrighted material is made available to anyone wishing to use, modify,
 *  copy, or redistribute it subject to the terms and conditions of the GNU GENERAL PUBLICLICENSE, as published by the Free Software Foundation.
 *
 *  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 distribution; if not, write to:
 *    Free Software Foundation, Inc.
 *    51 Franklin Street, Fifth Floor
 */

import java.util.List;

public class Main {
    public static String concatenate(String[] elements, String delimiter) {
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < elements.length; i++) {
            String element = elements[i];

            if (i > 0) {
                out.append(delimiter);
            }
            out.append(element);
        }
        return out.toString();
    }

    public static String concatenate(List<String> elements, String delimiter) {
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < elements.size(); i++) {
            String element = elements.get(i);

            if (i > 0) {
                out.append(delimiter);
            }
            out.append(element);
        }
        return out.toString();
    }
}

Related

  1. implode(String[] strings, String glue)
  2. makeDivideString(String[] arr_str, String divide_str)
  3. join(String spliter, Object[] arr)
  4. joinStrings(String joiner, Iterable parts)
  5. join(String spliter, Object[] arr)