Java List Join stringJoin(List list, String separator)

Here you can find the source of stringJoin(List list, String separator)

Description

Join a list of objects to a string with a given separator by calling Object.toString() on the elements.

License

Apache License

Parameter

Parameter Description
list to join
separator separator to use

Return

the joined string.

Declaration

public static String stringJoin(List list, String separator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**// www .  ja va 2s .com
     * Join a list of objects to a string with a given separator by calling Object.toString() on the elements.
     *
     * @param list to join
     * @param separator separator to use
     * @return the joined string.
     */
    public static String stringJoin(List list, String separator) {
        StringBuilder ret = new StringBuilder();
        boolean first = true;
        for (Object o : list) {
            if (!first) {
                ret.append(separator);
            }
            ret.append(o);
            first = false;
        }
        return ret.toString();
    }
}

Related

  1. listToText(List list, String join)
  2. orderJoinType(List jList)
  3. reverseJoinType(List jList)
  4. sortAndJoin(List col, String sep)
  5. sortAndJoin(List list)
  6. stringJoin(List list, String sep)
  7. trimAndJoin(List values, String delimiter)

    HOME | Copyright © www.java2s.com 2016