Here you can find the source of join(Collection
Parameter | Description |
---|---|
items | the String items to serialise into a string |
join | the String used between each string item in the list |
public static String join(Collection<String> items, String join)
//package com.java2s; /*/*from w w w . ja v a 2 s . co m*/ * Copyright 2010-2011 Heads Up Development Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; public class Main { /** * Join elements of a String collection into a single string. * The provided join String is used to between each item (i.e. ",") * * @param items the String items to serialise into a string * @param join the String used between each string item in the list * @return A single string where the items are appended together with "join" seperators */ public static String join(Collection<String> items, String join) { StringBuilder list = new StringBuilder(); boolean first = true; for (String type : items) { if (!first) { list.append(join); } list.append(type); first = false; } return list.toString(); } }