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

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

Description

join

License

Open Source License

Declaration

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

Method Source Code

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

import java.util.Arrays;

import java.util.List;

public class Main {
    public static String join(String separator, Object... objects) {
        StringBuilder sb = new StringBuilder();

        for (Object o : objects) {
            sb.append(o.toString()).append(separator);
        }/*  w  ww . ja  va  2  s .  c om*/
        return sb.toString().trim();
    }

    public static String join(String separator, List<String> tokens) {
        if (tokens.size() == 1)
            return tokens.get(0);

        StringBuilder sb = new StringBuilder();

        for (String token : tokens) {
            sb.append(token).append(separator);
        }

        return sb.toString().trim();
    }

    public static String join(String separator, String[] tokens) {
        return join(separator, Arrays.asList(tokens));
    }
}

Related

  1. join(String s, Object... objects)
  2. join(String sep, Object... pieces)
  3. join(String separator, CharSequence... elements)
  4. join(String separator, Collection strings)
  5. join(String separator, List objects)
  6. join(String separator, String... parts)
  7. join(String separator, String... strings)
  8. join(String separator, String... strings)
  9. join(String splitter, String... strs)