Java Collection Join join(String delimiter, Collection objects)

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

Description

join

License

Apache License

Declaration

public static String join(String delimiter, Collection<? extends 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, Collection<? extends Object> objects) {
        if (objects == null || objects.isEmpty()) {
            return EMPTY_STRING;
        }//w  w  w  .j av  a 2s .  c  om
        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();
    }

    public static String join(String delimiter, Object... objects) {
        return join(delimiter, Arrays.asList(objects));
    }
}

Related

  1. join(String delim, Collection values)
  2. join(String delim, Collection collections)
  3. join(String delim, Collection values)
  4. join(String delimeter, Collection items)
  5. join(String delimiter, Collection objects)
  6. join(String delimiter, Collection a)
  7. join(String delimiter, Collection items)
  8. join(String delimiter, Collection objects)
  9. join(String delimiter, Collection parts)