Java String Join join2(String connector, String... strs)

Here you can find the source of join2(String connector, String... strs)

Description

join

License

Open Source License

Declaration

public static String join2(String connector, String... strs) 

Method Source Code

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

import java.util.List;

public class Main {
    /** EMPTY [String] */
    public static final String EMPTY = "";

    public static String join2(String connector, String... strs) {

        StringBuffer sBuffer = new StringBuffer();

        for (Object object : strs) {
            sBuffer.append(object).append(connector);
        }/*from   w w w .j a v  a2s.c  o  m*/

        if (sBuffer.length() > 0) {
            sBuffer.delete(sBuffer.length() - connector.length(), sBuffer.length());
        }

        return sBuffer.toString();
    }

    public static String join2(String connector, List<Object> objects) {

        StringBuffer sBuffer = new StringBuffer();

        for (Object object : objects) {
            sBuffer.append(object).append(connector);
        }

        if (sBuffer.length() > 0) {
            sBuffer.delete(sBuffer.length() - connector.length(), sBuffer.length());
        }

        return sBuffer.toString();
    }

    public static String toString(Object object) {

        return object == null ? EMPTY : object.toString();
    }
}

Related

  1. join(String splitter, String... strs)
  2. join(String str[], String splitter)
  3. join(String... paths)
  4. join(String... xs)
  5. join(T delimiter, List list)
  6. joinColumns(Iterable columns)
  7. joinedList(T first, T... others)
  8. joinIterable(Iterable element, String separator)
  9. joinMap(Map map)