Java Collection to String toString(final Collection list, final String delimiter)

Here you can find the source of toString(final Collection list, final String delimiter)

Description

Returns the list of strings as a single string

License

Open Source License

Parameter

Parameter Description
list the list of strings
delimiter the delimiter

Return

the list as string

Declaration

public static String toString(final Collection<String> list, final String delimiter) 

Method Source Code

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

import java.util.Collection;

public class Main {
    public static final String DELIMITER = ", ";

    /**//from   w  ww  .j  a  v  a  2s  .  c o  m
     * Returns the list of strings as a single string
     * @param list the list of strings
     * @param delimiter the delimiter
     * @return the list as string
     */
    public static String toString(final Collection<String> list, final String delimiter) {
        final StringBuilder sb = new StringBuilder();
        for (final String string : list) {
            sb.append(string).append(delimiter);
        }
        sb.setLength(sb.length() - delimiter.length());
        return sb.toString();
    }

    /**
     * Returns the list of strings as a single string
     * @param list the list of strings
     * @return the list as string
     */
    public static String toString(final Collection<String> list) {
        return toString(list, DELIMITER);
    }
}

Related

  1. toString(final Collection collection)
  2. toString(final Collection collection)
  3. toString(final Collection collection, final String separator)
  4. toString(final Collection objs)
  5. toString(final Collection values)
  6. toString(final Collection c)
  7. toString(String[] collection, char separator)
  8. toStrings(Collection vals)
  9. toStrings(Collection c)