Java ArrayList Join joinArrayList(List coll, String delimiter)

Here you can find the source of joinArrayList(List coll, String delimiter)

Description

join Array List

License

Open Source License

Parameter

Parameter Description
coll a parameter
delimiter a parameter

Declaration

public static String joinArrayList(List<String> coll, String delimiter) 

Method Source Code

//package com.java2s;
/**/* w  ww.ja  v  a 2 s.  c o  m*/
 *  Copyright (C) 2012 White Source (www.whitesourcesoftware.com)
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This patch 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this patch.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;
import java.util.List;

public class Main {
    /**
     * @param coll
     * @param delimiter
     * @return
     * 
     * @deprecated Consider using StringUtils instead. 
     */
    public static String joinArrayList(List<String> coll, String delimiter) {
        if (coll.isEmpty()) {
            return "";
        }
        StringBuilder sb = new StringBuilder();

        for (String x : coll) {
            sb.append(x).append(delimiter);
        }
        sb.delete(sb.length() - delimiter.length(), sb.length());

        return sb.toString();
    }

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }
}

Related

  1. join(ArrayList strings, String separator)
  2. join(final ArrayList array, final String separator)
  3. join(final ArrayList arry, final String with)
  4. join(final ArrayList parts, final char separator)
  5. join(String glue, ArrayList a)
  6. joinArrayList(String joiner, ArrayList array)
  7. joinCommandLine(ArrayList lsCmdl)
  8. joinList(ArrayList list, String joint)