Java Array to String arrayToString(String[] array, String separator)

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

Description

array To String

License

Open Source License

Declaration

public static String arrayToString(String[] array, String separator) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2010 Intel Corporation and others.
 * 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
 *
 * Contributors:/*from w  ww .  j av  a 2s.  c o  m*/
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/

public class Main {
    public static String arrayToString(String[] array, String separator) {
        return arrayToString((Object[]) array, separator);
    }

    public static String arrayToString(Object[] array, String separator) {
        if (array == null)
            return null;
        if (array.length == 0)
            return ""; //$NON-NLS-1$
        if (array.length == 1)
            return array[0].toString();
        StringBuffer buf = new StringBuffer();
        buf.append(array[0]);
        for (int i = 1; i < array.length; i++) {
            buf.append(separator).append(array[i]);
        }

        return buf.toString();
    }
}

Related

  1. arrayToString(String[] array)
  2. arrayToString(String[] array)
  3. arrayToString(String[] array)
  4. arrayToString(String[] array, int start, String delimiter)
  5. arrayToString(String[] array, String delim, boolean quotes)
  6. arrayToString(String[] array, String separator)
  7. arrayToString(String[] array, String separators)
  8. arrayToString(String[] arrayString, String splitStr)
  9. arrayToString(String[] input)