Java String Join join(String connector, Object... objects)

Here you can find the source of join(String connector, Object... objects)

Description

join

License

Open Source License

Declaration

public static String join(String connector, Object... objects) 

Method Source Code

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

import java.util.List;

import java.util.Set;

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

    public static String join(String connector, Object... objects) {

        StringBuffer sBuffer = new StringBuffer();

        for (Object object : objects) {
            sBuffer.append(object).append(connector);
        }//from   w ww .  j a v  a 2s. c  o m

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

        return sBuffer.toString();
    }

    public static String join(String connector, String[] arr) {

        StringBuffer sBuffer = new StringBuffer();

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

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

        return sBuffer.toString();
    }

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

        StringBuffer sBuffer = new StringBuffer();

        for (String 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 join(String connector, Set<String> objects) {

        StringBuffer sBuffer = new StringBuffer();

        for (String 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(HashMap params, String separator)
  2. join(Iterable arr, String delimeter)
  3. join(Iterable input)
  4. join(java.util.Collection strings, String delimiter)
  5. join(Map map, String separator)
  6. join(String delim, List strings)
  7. join(String delim, Object... objects)
  8. join(String delimiter, Collection objects)
  9. join(String delimiter, Collection items)