Here you can find the source of joinToStringBuilder(Collection> collection, String separator)
Parameter | Description |
---|---|
collection | An Collection of objects |
separator | The separating character |
public static StringBuilder joinToStringBuilder(Collection<?> collection, String separator)
//package com.java2s; /*//from ww w . j a v a 2 s . c om * Copyright (c) Thomas Parker, 2007, 2008. * portions derived from CoreUtility.java * Copyright 2002 (C) Bryan McRoberts <merton_monk@yahoo.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * */ import java.util.Collection; public class Main { /** * Concatenates the Collection of Objects (converted to Strings using * .toString()) into a StringBuilder using the separator as the delimiter. * * This method is value-semantic and will not modify or maintain a reference * to the given Collection of Objects. Ownership of the returned * StringBuilder is transferred to the calling object. No reference to the * StringBuilder is maintained by StringUtil. * * @param collection * An Collection of objects * @param separator * The separating character * @return A 'separator' separated StringBuilder */ public static StringBuilder joinToStringBuilder(Collection<?> collection, String separator) { if (collection == null) { return new StringBuilder(); } StringBuilder result = new StringBuilder(collection.size() * 10); boolean needjoin = false; for (Object obj : collection) { if (needjoin) { result.append(separator); } needjoin = true; result.append(obj.toString()); } return result; } }