Java Collection Join join(Collection collection)

Here you can find the source of join(Collection collection)

Description

This method joins each value in the collection with a tab character as the delimiter.

License

Open Source License

Parameter

Parameter Description
collection a parameter

Return

a String

Declaration

public static String join(Collection collection) 

Method Source Code

//package com.java2s;
/*//from   w  w w.jav a2  s.c  om
 * Copyright (c) 2007-2010 Concurrent, Inc. All Rights Reserved.
 *
 * Project and contact information: http://www.cascading.org/
 *
 * This file is part of the Cascading project.
 *
 * Cascading is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cascading 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 Cascading.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

public class Main {
    /**
     * This method joins the values in the given list with the delim String value.
     *
     * @param list
     * @param delim
     * @return String
     */
    public static String join(int[] list, String delim) {
        return join(list, delim, false);
    }

    public static String join(int[] list, String delim, boolean printNull) {
        StringBuffer buffer = new StringBuffer();
        int count = 0;

        for (Object s : list) {
            if (count != 0)
                buffer.append(delim);

            if (printNull || s != null)
                buffer.append(s);

            count++;
        }

        return buffer.toString();
    }

    public static String join(String delim, String... strings) {
        return join(delim, false, strings);
    }

    public static String join(String delim, boolean printNull, String... strings) {
        return join(strings, delim, printNull);
    }

    /**
     * This method joins the values in the given list with the delim String value.
     *
     * @param list
     * @param delim
     * @return a String
     */
    public static String join(Object[] list, String delim) {
        return join(list, delim, false);
    }

    public static String join(Object[] list, String delim, boolean printNull) {
        StringBuffer buffer = new StringBuffer();
        int count = 0;

        for (Object s : list) {
            if (count != 0)
                buffer.append(delim);

            if (printNull || s != null)
                buffer.append(s);

            count++;
        }

        return buffer.toString();
    }

    /**
     * This method joins each value in the collection with a tab character as the delimiter.
     *
     * @param collection
     * @return a String
     */
    public static String join(Collection collection) {
        return join(collection, "\t");
    }

    /**
     * This method joins each valuein the collection with the given delimiter.
     *
     * @param collection
     * @param delim
     * @return a String
     */
    public static String join(Collection collection, String delim) {
        return join(collection, delim, false);
    }

    public static String join(Collection collection, String delim, boolean printNull) {
        StringBuffer buffer = new StringBuffer();

        join(buffer, collection, delim, printNull);

        return buffer.toString();
    }

    /**
     * This method joins each value in the collection with the given delimiter. All results are appended to the
     * given {@link StringBuffer} instance.
     *
     * @param buffer
     * @param collection
     * @param delim
     */
    public static void join(StringBuffer buffer, Collection collection, String delim) {
        join(buffer, collection, delim, false);
    }

    public static void join(StringBuffer buffer, Collection collection, String delim, boolean printNull) {
        int count = 0;

        for (Object s : collection) {
            if (count != 0)
                buffer.append(delim);

            if (printNull || s != null)
                buffer.append(s);

            count++;
        }
    }
}

Related

  1. join(Collection c, String delim)
  2. join(Collection c, String left, String right, String separator)
  3. join(Collection c, String separator)
  4. join(Collection col, char sep)
  5. join(Collection coll, String separator)
  6. join(Collection collection, String separator)
  7. join(Collection collection, String separator)
  8. join(Collection collection, String separator)
  9. join(Collection collection, String separator)