Here you can find the source of combineStrings(String[] strings)
Parameter | Description |
---|---|
strings | the array of strings |
null
if the array is empty.
public static String combineStrings(String[] strings)
//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(); } }