Java Collection Join join(String separator, Collection strings)

Here you can find the source of join(String separator, Collection strings)

Description

join

License

Open Source License

Declaration

public static String join(String separator, Collection<String> strings) 

Method Source Code


//package com.java2s;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright (c) 2012, Robin Jarry. All rights reserved.               *
 *                                                                     *
 * This file is part of APIWATCH and published under the BSD license.  *
 *                                                                     *
 * See the "LICENSE" file for more information.                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

import java.util.Collection;

public class Main {
    public static String join(String separator, Collection<String> strings) {
        if (separator == null) {
            throw new IllegalArgumentException("separator cannot be null");
        }//from  ww w. j ava  2 s .  com
        if (strings != null && strings.size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (String s : strings) {
                sb.append(separator);
                sb.append(s);
            }
            return sb.substring(separator.length());
        } else {
            return "";
        }
    }
}

Related

  1. join(String separator, Collection items)
  2. join(String separator, Collection items)
  3. join(String separator, Collection objs)
  4. join(String separator, Collection list)
  5. join(String separator, Collection parts)
  6. join(String separator, Collection objects)
  7. join(String separator, Collection values)
  8. join(String token, Collection strings)
  9. join(String[] collection, String delimiter)