Here you can find the source of join(String separator, Collection> objs)
Parameter | Description |
---|---|
separator | A separater to be inserted. |
objs | A collection of objects to be joined. |
public static String join(String separator, Collection<?> objs)
//package com.java2s; /*/* w ww . java2 s . co m*/ * Copyright (c) 2014-2015 NEC Corporation * 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 */ import java.util.Collection; public class Main { /** * Stringify the given objects, and join them with inserting the given * separator. * * @param separator A separater to be inserted. * @param objs Objects to be joined. * @return A joined string. */ public static String join(String separator, Object... objs) { StringBuilder builder = new StringBuilder(); String sep = ""; if (objs != null) { for (Object o : objs) { builder.append(sep).append(String.valueOf(o)); sep = separator; } } return builder.toString(); } /** * Stringify all the elements in the given collection, and join them with * inserting the given separator. * * @param separator A separater to be inserted. * @param objs A collection of objects to be joined. * @return A joined string. */ public static String join(String separator, Collection<?> objs) { StringBuilder builder = new StringBuilder(); String sep = ""; if (objs != null) { for (Object o : objs) { builder.append(sep).append(String.valueOf(o)); sep = separator; } } return builder.toString(); } }