Java Collection Join join(Collection items, String delim)

Here you can find the source of join(Collection items, String delim)

Description

join

License

Open Source License

Declaration

public static String join(Collection<?> items, String delim) 

Method Source Code


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

import java.util.Collection;

public class Main {
    public static String join(Collection<?> items, String delim) {
        if (items.isEmpty()) {
            return "";
        }//from  ww  w .j av a 2s.co m

        StringBuilder sb = new StringBuilder();

        for (Object o : items) {
            sb.append(o.toString());
            sb.append(delim);
        }

        sb.delete(sb.length() - delim.length(), sb.length());

        return sb.toString();
    }
}

Related

  1. join(Collection collection, String separator)
  2. join(Collection collection, String separator)
  3. join(Collection collection, String separatorString)
  4. join(Collection elements, String separator)
  5. join(Collection items, char separator)
  6. join(Collection items, String delimiter)
  7. join(Collection iterable, String delimiter)
  8. join(Collection objects, String token, StringBuilder buf)
  9. join(Collection objectsToJoin, String separator)