Java Collection Join joinCol(Collection lst, String delim)

Here you can find the source of joinCol(Collection lst, String delim)

Description

split into separate method so we don't get any accidental recursion between join(list) and join(collection).

License

Open Source License

Parameter

Parameter Description
lst a parameter
delim a parameter

Declaration

private static String joinCol(Collection lst, String delim) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//  www.jav a2 s .com
     * split into separate method so we don't get any accidental recursion
     * between join(list) and join(collection).
     * @param lst
     * @param delim
     * @return
     */
    private static String joinCol(Collection lst, String delim) {
        StringBuilder builder = new StringBuilder();
        for (Object obj : lst) {
            if (obj != null)
                builder.append(obj.toString());
            builder.append(delim);
        }

        builder.delete(builder.length() - delim.length(), builder.length());
        return builder.toString();
    }
}

Related

  1. join(StringBuilder builder, Collection strs)
  2. join2(Collection list, String delimiter)
  3. joinAndDelimit(final Collection strings, final String sep, final String delim)
  4. joinAsString(Collection collection, String separator)
  5. joinAsStrings(Collection values, String separator)
  6. joinCollection(Collection collection, char delimiter)
  7. joinCollection(Collection a)
  8. joinCollections(final Collection target, final Collection... collections)
  9. joinCollectionToString(Collection list, String str)