Java Collection Join join(final Collection toJoin)

Here you can find the source of join(final Collection toJoin)

Description

join

License

Open Source License

Declaration

static String join(final Collection<String> toJoin) 

Method Source Code

//package com.java2s;
/*/*from   w  ww .j  a  v a 2 s .  c  o m*/
 * Copyright (c) 2007-2013 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    static String join(final Collection<String> toJoin) {
        if (toJoin == null) {
            return null;
        }

        final String separator = ",";
        final StringBuffer buf = new StringBuffer(256);
        final Iterator<String> iterator = toJoin.iterator();
        while (iterator.hasNext()) {
            buf.append(iterator.next());
            if (iterator.hasNext()) {
                buf.append(separator);
            }
        }
        return buf.toString();
    }
}

Related

  1. join(final Collection chunks, final String delimiter)
  2. join(final Collection collection, final String separator)
  3. join(final Collection list, final String separator)
  4. join(final Collection seq, final String delimiter)
  5. join(final Collection strs, final String delimiter)
  6. join(final Collection values)
  7. join(final Collection values, final char separator)
  8. join(final Collection collection)
  9. join(final Collection collection, final String delimiter)