Java String Array Combine combineStrings(String[] strings)

Here you can find the source of combineStrings(String[] strings)

Description

Returns a single-string of the strings for storage.

License

Open Source License

Parameter

Parameter Description
strings the array of strings

Return

a single-string representation of the strings or null if the array is empty.

Declaration

public static String combineStrings(String[] strings) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2011 IBM 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  w  w .j a  v  a2 s.c  o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

    /**
     * Returns a single-string of the strings for storage.
     * 
     * @param strings
     *            the array of strings
     * @return a single-string representation of the strings or
     *         <code>null</code> if the array is empty.
     */
    public static String combineStrings(String[] strings) {
        if (strings.length == 0)
            return null;

        if (strings.length == 1)
            return strings[0];

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < strings.length - 1; i++) {
            buf.append(strings[i]);
            buf.append(ATTRIBUTE_SEPARATOR);
        }
        buf.append(strings[strings.length - 1]);
        return buf.toString();
    }
}

Related

  1. combineSplit(int startIndex, String[] string, String separator)
  2. combineString(String[] strArr, String glue)
  3. combineStringArray(String[] array, String delim)
  4. combineStrings(Object... strings)
  5. combineStrings(Object[] list)