Java List Join join(List s, String delimiter)

Here you can find the source of join(List s, String delimiter)

Description

join

License

Open Source License

Declaration

public static String join(List<? extends CharSequence> s, String delimiter) 

Method Source Code

//package com.java2s;

import java.util.Iterator;
import java.util.List;

public class Main {
    public static String join(List<? extends CharSequence> s, String delimiter) {
        int capacity = 0;
        int delimLength = delimiter.length();
        Iterator<? extends CharSequence> iter = s.iterator();
        if (iter.hasNext()) {
            capacity += iter.next().length() + delimLength;
        }//from w  w  w .j  a v a 2 s . c  o m

        StringBuilder buffer = new StringBuilder(capacity);
        iter = s.iterator();
        if (iter.hasNext()) {
            buffer.append(iter.next());
            while (iter.hasNext()) {
                buffer.append(delimiter);
                buffer.append(iter.next());
            }
        }
        return buffer.toString();
    }
}

Related

  1. join(List objects, String joiner)
  2. join(List strings, String delimiter)
  3. join(List vec, String separator)
  4. join(List items, CharSequence delimiter)
  5. join(List s, String delimiter)
  6. join(List items, String conjunction)
  7. join(List items, String separator)
  8. join(List list)
  9. join(List olist, String glue)