Here you can find the source of join(final Collection extends Object> items, final String glue)
Parameter | Description |
---|---|
items | the Collection of items that will be joined together |
glue | the string to act as glue in the concatenation |
public static String join(final Collection<? extends Object> items, final String glue)
//package com.java2s; /**/*from ww w .j av a 2s .c o m*/ * Copyright (c) 2009 Stephen Evanchik * 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: * Stephen Evanchik - initial implementation */ import java.util.Collection; public class Main { /** * Implementation of join using a {@link StringBuffer} * * @param items * the {@link Collection} of items that will be joined together * @param glue * the string to act as glue in the concatenation * @return the concatenation of the specified items */ public static String join(final Collection<? extends Object> items, final String glue) { final StringBuffer buffer = new StringBuffer(); for (final Object o : items) { if (buffer.length() > 0) { buffer.append(glue); } buffer.append(o.toString()); } return buffer.toString(); } }