Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Pascal Essiembre. * 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: * Pascal Essiembre - initial API and implementation ******************************************************************************/ public class Main { /** * Joins an array by the given separator. * * @param array * the array to join * @param separator * the joining separator * @return joined string */ public static String join(Object[] array, String separator) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < array.length; i++) { Object item = array[i]; if (item != null) { if (buf.length() > 0) { buf.append(separator); } buf.append(item); } } return buf.toString(); } }