Java List Join join(List list)

Here you can find the source of join(List list)

Description

join

License

Open Source License

Declaration

public static String join(List<String> list) 

Method Source Code

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

import java.util.List;

public class Main {
    public static String join(List<String> list) {
        return join(list, null);
    }// ww w .j a  v a  2s . c o  m

    public static String join(List<String> list, char separator) {
        return join(list, String.valueOf(separator));
    }

    public static String join(List<String> list, String separator) {
        if (list == null) {
            return null;
        }
        if (list.isEmpty()) {
            return "";
        }
        int seplen;
        if (separator == null) {
            seplen = 0;
        } else {
            seplen = separator.length();
        }
        int len = -seplen;
        for (String s : list) {
            len += seplen;
            if (s != null) {
                len += s.length();
            }
        }
        StringBuffer buf = new StringBuffer(len);
        boolean first = true;
        for (String s : list) {
            if (first) {
                first = false;
            } else {
                if (seplen != 0) {
                    buf.append(separator);
                }
            }
            if (s != null) {
                buf.append(s);
            }
        }
        return buf.toString();
    }
}

Related

  1. join(List command, List args)
  2. join(List elements)
  3. join(List items, char separator)
  4. join(List l, String joiner)
  5. join(List lines, char delim)
  6. join(List list)
  7. join(List list)
  8. join(List list)
  9. join(List list)