Here you can find the source of join(Collection
Parameter | Description |
---|---|
strings | The Collection of strings to join. |
public static String join(Collection<String> strings)
//package com.java2s; /*/*from w ww. j av a 2 s. c o m*/ Copyright: 2010 Bindley Bioscience Center, Purdue University License: X11 license. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.util.Collection; public class Main { /** * Joins a Collection of strings into a single string, inserting a space * between each one. * * @param strings The Collection of strings to join. * @return The resulting string. */ public static String join(Collection<String> strings) { return join(strings, " "); } /** * Joins a Collection of strings into a single string, inserting a separator * string between each one. * * @param strings The Collection of strings to join. * @param separator The separator to use between strings. * @return The resulting string. */ public static String join(Collection<String> strings, String separator) { StringBuilder returnValue = new StringBuilder(); for (String string : strings) { if (returnValue.length() > 0) { returnValue.append(separator); } returnValue.append(string); } return returnValue.toString(); } /** * Converts a character to a String. * * @param c The character to be converted. * @return A string containing a single character. */ public static String toString(char c) { return new StringBuilder().append(c).toString(); } }