Here you can find the source of join(final Iterable extends Object> iterable, final CharSequence separator)
Parameter | Description |
---|---|
iterable | The Iterable number of objects |
separator | a parameter |
public static String join(final Iterable<? extends Object> iterable, final CharSequence separator)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2013 compeople AG 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:/* w ww. j av a 2 s . c om*/ * compeople AG - initial API and implementation *******************************************************************************/ import java.util.Iterator; public class Main { /** * Joins the string representations of an {@link Iterable} collection of * objects to one continues string while separating the entities with the * provided separator. * <p> * The string representation will be retrieved by String.valueOf() * * @param iterable * The {@link Iterable} number of objects * @param separator * @return The joined String separated by the given separator * @since 3.0 */ public static String join(final Iterable<? extends Object> iterable, final CharSequence separator) { Iterator<? extends Object> oIt; if (iterable == null || (!(oIt = iterable.iterator()).hasNext())) { return ""; //$NON-NLS-1$ } final StringBuilder sb = new StringBuilder(String.valueOf(oIt.next())); while (oIt.hasNext()) { sb.append(separator).append(oIt.next()); } return sb.toString(); } }