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

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

Description

join

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.Collection;

import java.util.Iterator;

public class Main {
    public static final String EMPTY_STRING = "";

    public static String join(String delimiter, Object... objects) {
        return join(delimiter, Arrays.asList(objects));
    }/*from   w ww .j a  v  a2s.co m*/

    public static String join(String delimiter, Collection<? extends Object> objects) {
        if (objects == null || objects.isEmpty()) {
            return EMPTY_STRING;
        }
        Iterator<? extends Object> iterator = objects.iterator();
        StringBuilder builder = new StringBuilder();
        builder.append(iterator.next());
        while (iterator.hasNext()) {
            builder.append(delimiter).append(iterator.next());
        }
        return builder.toString();
    }
}

Related

  1. join(String delimiter, Collection objects)
  2. join(String delimiter, Collection items)
  3. join(String delimiter, Iterable elements)
  4. join(String delimiter, Iterable strings)
  5. join(String delimiter, Iterable strings)
  6. join(String delimiter, Object... parts)
  7. join(String delimiter, String... items)
  8. join(String delimiter, String... params)
  9. join(String delimiter, String... strings)