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

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

Description

join

License

Open Source License

Declaration

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

Method Source Code


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

import java.util.List;

public class Main {

    public static String join(String s, Object... objects) {
        if (objects.length == 0) {
            return "";
        }//from   w  ww. j a va2  s .  c o m
        StringBuilder sb = new StringBuilder(objects[0].toString());
        for (int i = 1; i < objects.length; i++) {
            sb.append(s).append(objects[i]);
        }
        return sb.toString();
    }

    public static String join(String s, List ls) {
        if (ls.size() == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder(ls.get(0).toString());
        for (int i = 1; i < ls.size(); i++) {
            sb.append(s).append(ls.get(i));
        }
        return sb.toString();
    }
}

Related

  1. join(String delimiter, String... strings)
  2. join(String delimiter, T... array)
  3. join(String glue, Iterable items)
  4. join(String glue, String... str)
  5. join(String joiner, String... toJoin)
  6. join(String sep, Object... pieces)
  7. join(String separator, CharSequence... elements)
  8. join(String separator, Collection strings)
  9. join(String separator, List objects)