Java Array Join join(Object[] array, String separator)

Here you can find the source of join(Object[] array, String separator)

Description

Join the objects in array with the given separator Useful for making a comma separated list, or URL query string

License

LGPL

Parameter

Parameter Description
array a parameter
separator a parameter

Declaration

public static String join(Object[] array, String separator) 

Method Source Code

//package com.java2s;
/*/*  www .j  ava 2  s. c  o  m*/
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

import java.util.List;

public class Main {
    public static String join(List list, String separator) {
        return join(list.toArray(), separator);
    }

    /**
     * Join the objects in {@code array} with the given {@code separator}
     * Useful for making a comma separated list, or URL query string
     * @param array
     * @param separator
     * @return
     */
    public static String join(Object[] array, String separator) {
        int num = array.length;
        if (num == 0)
            return "";
        String out = array[0].toString();
        for (int ii = 1; ii < num; ii++) {
            out += (separator + array[ii].toString());
        }
        return out;
    }
}

Related

  1. join(Object[] array, String separator)
  2. join(Object[] array, String separator)
  3. join(Object[] array, String separator)
  4. join(Object[] array, String separator)
  5. join(Object[] array, String separator)
  6. join(Object[] array, String separator)
  7. join(Object[] array, String separator)
  8. join(Object[] array, String seperator)
  9. join(Object[] elements, CharSequence separator)