Here you can find the source of join(final Collection
static String join(final Collection<String> values)
//package com.java2s; /*//ww w . j av a2 s .c o m * Copyright 2011-2012 Amazon Technologies, Inc. * * 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://aws.amazon.com/apache2.0 * * This file 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 { /** * Joins a collection of values with commas, enclosed by brackets. An empty * or null set of values returns the empty string. */ static String join(final Collection<String> values) { return join(values, false); } /** * Joins a collection of values with commas, enclosed by brackets. An empty * or null set of values returns the empty string. * * @param quoted * Whether each value should be quoted in the output. */ static String join(final Collection<String> values, boolean quoted) { if (values == null || values.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder("{"); boolean seenOne = false; for (String s : values) { if (seenOne) { builder.append(","); } else { seenOne = true; } builder.append(quoted ? "\"" + s + "\"" : s); } builder.append("}"); return builder.toString(); } }