Java Collection Join join(Collection c, String delimiter)

Here you can find the source of join(Collection c, String delimiter)

Description

Returns a String formed by the delimited results of calling toString over a collection.

License

GNU General Public License

Parameter

Parameter Description
c the collection to stringify
delimiter the character to join on

Return

the string representation

Declaration

public static String join(Collection<?> c, String delimiter) 

Method Source Code

//package com.java2s;
/*// w w w.ja v  a 2s. co m
 * Copyright (C) 2002-2017 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.Collection;

public class Main {
    /**
     * Returns a String formed by the delimited results of calling toString over a collection.
     *
     * @param c the collection to stringify
     * @param delimiter the character to join on
     * @return the string representation
     */
    public static String join(Collection<?> c, String delimiter) {
        StringBuffer sb = new StringBuffer();
        boolean needComma = false;
        for (Object o : c) {
            if (needComma) {
                sb.append(delimiter);
            }
            needComma = true;
            sb.append(o.toString());
        }
        return sb.toString();
    }
}

Related

  1. join(Collection list, String separator)
  2. join(Collection objects, String delim)
  3. join(Collection strings, String separator)
  4. join(Collection strs, String separator)
  5. join(Collection c, String delim)
  6. join(Collection c, String insert)
  7. join(Collection c, String separator)
  8. join(Collection col, String delim)
  9. join(Collection col, String separator)