Java Collection Convert toStringBuilder( Collection collection, String delimiter)

Here you can find the source of toStringBuilder( Collection collection, String delimiter)

Description

Transform a collection of objects to a delimited String.

License

Apache License

Parameter

Parameter Description
collection the collection to transform.
delimiter the delimiter used to delimit the Strings.

Return

a StringBuilder with all the elements of the collection.

Declaration

public static StringBuilder toStringBuilder(
        Collection<? extends Object> collection, String delimiter) 

Method Source Code

//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;
    }
}

Related

  1. toSeparatedString(Collection items, String separator)
  2. toSeperatedString(final Collection list)
  3. toSet(Collection c)
  4. toSingleton(Collection l)
  5. toSQLIn(Collection values)
  6. toStringColl(Collection set)
  7. toSV(Collection collection, String separator)
  8. toTestParameters(Collection rawParams)
  9. toToolTip(final Collection collection)