Java List Join joinStrings(Iterable list)

Here you can find the source of joinStrings(Iterable list)

Description

same as #joinStrings(Iterable,String) , and default sep to empty string

License

Open Source License

Declaration

public static String joinStrings(Iterable<String> list) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    /**//  ww  w. ja  v  a2 s . co m
     * same as {@link #joinStrings(Iterable, String)}, and default {@code sep} to empty string
     */
    public static String joinStrings(Iterable<String> list) {
        return joinStrings(list, "");
    }

    /**
     * join a list of string to a string with {@code sep}.
     * 
     * @param list the string list
     * @param sep the separator 
     */
    public static String joinStrings(Iterable<String> list, String sep) {
        if (list == null)
            return "";

        StringBuffer sb = new StringBuffer();

        for (Iterator<String> it = list.iterator(); it.hasNext();) {
            sb.append(it.next());

            if (it.hasNext()) {
                sb.append(sep);
            }
        }

        return sb.toString();
    }
}

Related

  1. joinString(java.util.List values, String delimiter)
  2. joinString(List array, String symbol)
  3. joinString(List objs, String separator)
  4. joinString(List val, String delim)
  5. joinStringList(String delimiter, List stringList)
  6. joinStrings(List aList, String aString)
  7. joinStrings(List list, String delim)
  8. joinStrings(List strings, String separator)
  9. joinStrings(List strings, String separator)