Java Collection Join join(final Collection seq, final String delimiter)

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

Description

join

License

Open Source License

Declaration

public static String join(final Collection<String> seq, final String delimiter) 

Method Source Code

//package com.java2s;
/* Copyright c 2005-2012.
 * Licensed under GNU  LESSER General Public License, Version 3.
 * http://www.gnu.org/licenses/*from   ww w .  ja va 2 s.c o m*/
 */

import java.util.Collection;

public class Main {
    public static final String DELIMITER = ",";

    public static String join(final String[] seq, final String delimiter) {
        if (null == seq || seq.length < 1) {
            return "";
        } else {
            StringBuilder aim = new StringBuilder();
            for (int i = 0; i < seq.length; i++) {
                if (null != delimiter && aim.length() > 0) {
                    aim.append(delimiter);
                }
                aim.append(seq[i]);
            }
            return aim.toString();
        }
    }

    public static String join(final Collection<String> seq, final String delimiter) {
        if (null == seq || seq.size() < 1) {
            return "";
        } else {
            StringBuilder aim = new StringBuilder();
            for (String one : seq) {
                if (null != delimiter && aim.length() > 0) {
                    aim.append(delimiter);
                }
                aim.append(one);
            }
            return aim.toString();
        }
    }

    public static String join(final String... seq) {
        return join(seq, DELIMITER);
    }
}

Related

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

  10. HOME | Copyright © www.java2s.com 2016