Here you can find the source of toStringBuilder( Collection extends Object> collection, String delimiter)
Parameter | Description |
---|---|
collection | the collection to transform. |
delimiter | the delimiter used to delimit the Strings. |
public static StringBuilder toStringBuilder( Collection<? extends Object> collection, String delimiter)
//package com.java2s; /**//from w w w . j a v a 2s.c o m * * Copyright 2003-2007 Jive Software, 2016 Florian Schmaus. * * 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; import java.util.Iterator; public class Main { /** * Transform a collection of objects to a delimited String. * * @param collection the collection to transform. * @param delimiter the delimiter used to delimit the Strings. * @return a StringBuilder with all the elements of the collection. */ public static StringBuilder toStringBuilder( Collection<? extends Object> collection, String delimiter) { StringBuilder sb = new StringBuilder(collection.size() * 20); for (Iterator<? extends Object> it = collection.iterator(); it .hasNext();) { Object cs = it.next(); sb.append(cs); if (it.hasNext()) { sb.append(delimiter); } } return sb; } }