Here you can find the source of join(final Collection
Parameter | Description |
---|---|
values | the values to be joined. |
separator | the separator to separate values within the returned value. |
public static String join(final Collection<String> values, final char separator)
//package com.java2s; /*/*from w ww . ja v a 2 s . com*/ * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2010?2011 ApexIdentity Inc. * Portions Copyright 2011-2014 ForgeRock AS. */ import java.util.Collection; public class Main { /** * Joins a collection of header values into a single header value, with a specified * specified separator. A {@code null} or empty collection of header values yeilds a * {@code null} return value. * * @param values the values to be joined. * @param separator the separator to separate values within the returned value. * @return a single header value, with values separated by the separator. */ public static String join(final Collection<String> values, final char separator) { if (separator == '"' || separator == '\\') { throw new IllegalArgumentException("invalid separator: " + separator); } final StringBuilder sb = new StringBuilder(); if (values != null) { for (final String s : values) { if (s != null) { if (sb.length() > 0) { sb.append(separator).append(' '); } sb.append(s); } } } return sb.length() > 0 ? sb.toString() : null; } }