Android List Join concatenate(List elements, String delimiter)

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

Description

concatenate

License

GNU General Public License

Declaration

public static String concatenate(List<String> elements, String delimiter) 

Method Source Code

//package com.java2s;
/*//from   w  w  w.j a  va  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. join(List list, String glue)
  2. join(List s, String delimiter)
  3. implode(List strings, String glue)
  4. join(List texts, String separator)
  5. join(String separator, List data)
  6. toCommaSeperatedList(List values)
  7. implode(List list, String glue)
  8. joinList(String seperator, List list)
  9. joinList(String seperator, List list, String def)